首页 > 其他 > 详细

AtCoder Regular Contest 124

时间:2021-07-26 22:55:40      阅读:32      评论:0      收藏:0      [点我收藏+]

比赛链接:Here

A - LR Constraints

赛时做这个好迷啊,英文题面解释不清楚,还是看了日语原文才搞懂

\(n\) 个卡牌上有两个 字符 + 数字 组合,L 的右边所有元素 + 1,R 的左边元素 + 1

最后求出现过数字的乘积,同时对 \(998244353\) 取余

注意点:开 long long !!!,今天牛客也是,没开 ll debug半天,感谢尚佬指出我的错误

Show Code

const int N = 1010;
bool vis[N];
int cnt[N];
int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= k; ++i) {
        char c; int x;
        cin >> c >> x;
        if (c == ‘L‘) {
            vis[x] = 1;
            for (int j = x + 1; j <= n; ++j)cnt[j] ++;
        } else {
            vis[x] = 1;
            for (int j = 1; j <= x; ++j)cnt[j] ++;
        }

    }
    ll ans = 1;
    for (int i = 1; i <= n; ++i) {
        if (!vis[i])ans = ans * cnt[i] % 998244353;
    }
    cout << ans << ‘\n‘;
}

B - XOR Matching 2

对于长度为 \(n\)\(a,b\) 两个序列,请问是否存在某种排序组合使得某个 \(x\) 被称为 Good

Good定义:可以对 \(b\) 重排序使得每一个 \(a_i\ XOR\ b_i = x\)

\(x\) 固定时,置换 \(b\) 使得 \(a_i ⊕ b_i = x\) 等价于 \(c_i = a_i ⊕x\)

所以我们可以直接尝试 \(a_1 ⊕ b1,a_1 ⊕ b_2,...,a_1⊕b_n\)

  • \(\mathcal{O}(N^2log\ N)\)
Show Code

const int N = 2e3 + 10;
int a[N], b[N];
map<int, int> mp, bg;
set<int>v;
int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) cin >> b[i], bg[b[i]]++;
    for (int i = 1; i <= n; ++i) {
        int x = a[1] ^ b[i]; mp = bg;
        bool f = true;
        for (int j = 1; j <= n and f; ++j)if (!mp[x ^ a[j]]) f = false;
        if (f) v.insert(x);
    }
    cout << v.size() << "\n";
    for (int x : v)cout << x << "\n";
}

AtCoder Regular Contest 124

原文:https://www.cnblogs.com/RioTian/p/15063152.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!