Submission #29338202


Source Code Expand

// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint998244353;
// using mint = modint1000000007;
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,k,n) for (int i = (k); i < (n); ++i)
using namespace std;
using ll = long long;
// using P = pair<ll,ll>;
using P = pair<int,int>;
using vint = vector<int>;
using vll = vector<ll>;
using vvint = vector<vector<int>>;
using vvll = vector<vector<ll>>;

// const ll INF = (ll)2e18+9;
const int INF = (int)2e9+7;
// const ll MOD = (ll)1e9+9;
template<typename T>
void chmin(T &a, T b) { a = min(a, b); }
template<typename T>
void chmax(T &a, T b) { a = max(a, b); }

template<typename T>
void print(vector<T> v) {
    int n = v.size();
    rep(i,n) {
        if (i == 0) cout << v[i];
        else cout << ' ' << v[i];
    }
    cout << endl;
}

bool hasBit(ll x, int i) {
    return (x>>i)&1;
}

void solve() {
    int n;
    cin >> n;
    vll a(n);
    rep(i,n) cin >> a[i];

    ll ans = 0;
    rep(i,n) ans += a[i];

    vll nbits(30, 0);
    for (ll x : a) {
        rep(i,30) if (hasBit(x, i)) nbits[i]++;
    }

    for (ll x : a) {
        ll tot = 0;
        rep(i,30) {
            if (hasBit(x, i)) tot += (n- nbits[i]) * (1ll<<i);
            else tot += nbits[i] * (1ll<<i);
        }
        chmax(ans, tot);
    }
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}

Submission Info

Submission Time
Task C - XOR to All
User goropikari
Language C++ (GCC 9.2.1)
Score 500
Code Size 1550 Byte
Status AC
Exec Time 160 ms
Memory 5604 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 47
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 03_rand_01.txt, 03_rand_02.txt, 03_rand_03.txt, 03_rand_04.txt, 03_rand_05.txt, 03_rand_06.txt, 03_rand_07.txt, 03_rand_08.txt, 03_rand_09.txt, 03_rand_10.txt, 04_rand_biased_01.txt, 04_rand_biased_02.txt, 04_rand_biased_03.txt, 04_rand_biased_04.txt, 04_rand_biased_05.txt, 04_rand_biased_06.txt, 04_rand_biased_07.txt, 04_rand_biased_08.txt, 04_rand_biased_09.txt, 04_rand_biased_10.txt, 05_anti_greedy_01.txt, 05_anti_greedy_02.txt, 05_anti_greedy_03.txt, 05_anti_greedy_04.txt, 05_anti_greedy_05.txt, 05_anti_greedy_06.txt, 05_anti_greedy_07.txt, 05_anti_greedy_08.txt, 05_anti_greedy_09.txt, 05_anti_greedy_10.txt, 06_handmade_01.txt, 06_handmade_02.txt, 06_handmade_03.txt, 06_handmade_04.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 7 ms 3560 KiB
01_sample_02.txt AC 3 ms 3564 KiB
01_sample_03.txt AC 2 ms 3560 KiB
02_small_01.txt AC 2 ms 3380 KiB
02_small_02.txt AC 2 ms 3564 KiB
02_small_03.txt AC 3 ms 3448 KiB
02_small_04.txt AC 2 ms 3592 KiB
02_small_05.txt AC 2 ms 3444 KiB
02_small_06.txt AC 2 ms 3592 KiB
02_small_07.txt AC 2 ms 3572 KiB
02_small_08.txt AC 2 ms 3444 KiB
02_small_09.txt AC 2 ms 3512 KiB
02_small_10.txt AC 2 ms 3380 KiB
03_rand_01.txt AC 160 ms 5452 KiB
03_rand_02.txt AC 157 ms 5508 KiB
03_rand_03.txt AC 158 ms 5392 KiB
03_rand_04.txt AC 157 ms 5368 KiB
03_rand_05.txt AC 157 ms 5456 KiB
03_rand_06.txt AC 156 ms 5600 KiB
03_rand_07.txt AC 158 ms 5488 KiB
03_rand_08.txt AC 159 ms 5392 KiB
03_rand_09.txt AC 157 ms 5432 KiB
03_rand_10.txt AC 159 ms 5452 KiB
04_rand_biased_01.txt AC 140 ms 5548 KiB
04_rand_biased_02.txt AC 145 ms 5436 KiB
04_rand_biased_03.txt AC 150 ms 5448 KiB
04_rand_biased_04.txt AC 153 ms 5492 KiB
04_rand_biased_05.txt AC 149 ms 5368 KiB
04_rand_biased_06.txt AC 151 ms 5600 KiB
04_rand_biased_07.txt AC 151 ms 5452 KiB
04_rand_biased_08.txt AC 146 ms 5492 KiB
04_rand_biased_09.txt AC 148 ms 5368 KiB
04_rand_biased_10.txt AC 144 ms 5600 KiB
05_anti_greedy_01.txt AC 145 ms 5452 KiB
05_anti_greedy_02.txt AC 147 ms 5604 KiB
05_anti_greedy_03.txt AC 148 ms 5604 KiB
05_anti_greedy_04.txt AC 148 ms 5452 KiB
05_anti_greedy_05.txt AC 153 ms 5504 KiB
05_anti_greedy_06.txt AC 154 ms 5508 KiB
05_anti_greedy_07.txt AC 153 ms 5500 KiB
05_anti_greedy_08.txt AC 156 ms 5448 KiB
05_anti_greedy_09.txt AC 158 ms 5508 KiB
05_anti_greedy_10.txt AC 158 ms 5452 KiB
06_handmade_01.txt AC 3 ms 3460 KiB
06_handmade_02.txt AC 2 ms 3404 KiB
06_handmade_03.txt AC 57 ms 5392 KiB
06_handmade_04.txt AC 108 ms 5540 KiB