結果

問題 No.1900 Don't be Powers of 2
ユーザー 👑 colognecologne
提出日時 2022-04-08 21:59:02
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 875 bytes
コンパイル時間 3,109 ms
コンパイル使用メモリ 256,444 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-05-06 07:33:22
合計ジャッジ時間 4,363 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 42 ms
19,456 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 43 ms
19,456 KB
testcase_34 AC 43 ms
19,456 KB
testcase_35 AC 42 ms
19,456 KB
testcase_36 AC 40 ms
11,648 KB
testcase_37 AC 8 ms
5,376 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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)))
                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