답안 #823879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
823879 2023-08-13T09:24:02 Z borisAngelov XOR Sum (info1cup17_xorsum) C++17
77 / 100
1600 ms 21624 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1000005;

int n;
int a[maxn];

bool check(int bit)
{
    int result = 0;
    int cnt = 0;
    vector<int> rems;

    for (int i = 1; i <= n; ++i)
    {
        if ((a[i] & (1 << bit)) != 0)
        {
            ++cnt;
        }

        rems.push_back((a[i] % (1 << bit)));
    }

    result = (1LL * result + (1LL * cnt) * (1LL * (n - cnt))) % 2;

    sort(rems.begin(), rems.end());

    int r = n - 1;

    for (int l = 0; l < n; ++l)
    {
        if (l > r)
        {
            ++r;
        }

        while (r > l && rems[l] + rems[r - 1] >= (1 << bit))
        {
            --r;
        }

        if (rems[l] + rems[r] >= (1 << bit))
        {
            result = (result + n - r) % 2;
        }
    }

    return result;
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    cin >> n;
    int max_val = 0;

    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        max_val = max(max_val, a[i]);
    }

    int ans = 0;

    int up_to = 0;
    int curr = 1;

    while (curr < max_val)
    {
        ++up_to;
        curr *= 2;
    }

    for (int i = 0; i <= up_to; ++i)
    {
        if (check(i) == true)
        {
            ans += (1 << i);
        }
    }

    cout << ans << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 340 KB Output is correct
2 Correct 8 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 607 ms 12264 KB Output is correct
2 Correct 573 ms 11784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 607 ms 12264 KB Output is correct
2 Correct 573 ms 11784 KB Output is correct
3 Correct 1325 ms 12236 KB Output is correct
4 Correct 1176 ms 12188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 340 KB Output is correct
2 Correct 8 ms 340 KB Output is correct
3 Correct 187 ms 1656 KB Output is correct
4 Correct 185 ms 1652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 340 KB Output is correct
2 Correct 8 ms 340 KB Output is correct
3 Correct 607 ms 12264 KB Output is correct
4 Correct 573 ms 11784 KB Output is correct
5 Correct 1325 ms 12236 KB Output is correct
6 Correct 1176 ms 12188 KB Output is correct
7 Correct 187 ms 1656 KB Output is correct
8 Correct 185 ms 1652 KB Output is correct
9 Execution timed out 1654 ms 21624 KB Time limit exceeded
10 Halted 0 ms 0 KB -