結果

問題 No.1900 Don't be Powers of 2
ユーザー cologne
提出日時 2022-04-08 22:00:41
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 883 bytes
コンパイル時間 3,043 ms
コンパイル使用メモリ 257,392 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-11-28 12:40:58
合計ジャッジ時間 4,091 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/math>
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int &a : A)
        cin >> a;
    vector<vector<int>> V(N);
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
        {
            int k = A[j] ^ A[i];
            if (k == (k & (-k)) && k != 0)
                V[i].push_back(j);
        }
    vector<bool> vis(N);

    int c1 = 0, c2 = 0, ans = 0;
    function<void(int, bool)> dfs = [&](int x, bool p)
    {
        if (vis[x])
            return;
        vis[x] = 1;
        if (p)
            ++c1;
        else
            ++c2;
        for (auto y : V[x])
            dfs(y, !p);
    };

    for (int i = 0; i < N; i++)
        if (!vis[i])
        {
            dfs(i, 0);
            ans += max(c1, c2);
            c1 = c2 = 0;
        }

    cout << ans << endl;
}
0