結果

問題 No.1240 Or Sum of Xor Pair
ユーザー milanis48663220milanis48663220
提出日時 2020-09-25 23:25:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,935 bytes
コンパイル時間 754 ms
コンパイル使用メモリ 86,804 KB
実行使用メモリ 8,944 KB
最終ジャッジ日時 2023-09-10 16:21:40
合計ジャッジ時間 7,077 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,428 KB
testcase_01 AC 2 ms
5,388 KB
testcase_02 AC 2 ms
5,596 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 WA -
testcase_27 AC 2 ms
5,420 KB
testcase_28 AC 2 ms
5,552 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 16 ms
5,940 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int N;
int X;
int A[200000];
int lx, rx;
int la[200000], ra[200000];

// v[i]: left halfがiのlaたち
vector<int> v[1<<9];
ll v_cnt[1<<9][1<<9];

ll cnt[1<<9][9];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> X;
    lx = (X>>9);
    rx = (X&((1<<9)-1));
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        la[i] = (A[i]>>9);
        ra[i] = (A[i]&((1<<9)-1));
        v[la[i]].push_back(ra[i]);
        v_cnt[la[i]][ra[i]]++;
        for(int j = 0; j < 9; j++){
            if(ra[i] & (1<<j)) cnt[la[i]][j]++;
        }
    }
    ll ans = 0;
    ll th = 1000000;
    for(int i = 0; i < (1<<9); i++){
        ll cnt_i = v[i].size();
        ll tmp = 0;
        if(cnt_i*cnt_i < th){
            for(int k : v[i]){
                for(int l : v[i]){
                    if((k^l) < rx){
                        tmp += (i|i)*(1<<9);
                        tmp += (k|l);
                    }
                }
            }
        }else{
            for(int k = 0; k < (1<<9); k++){
                for(int l = 0; l < (1<<9); l++){
                    if((k^l) < rx){
                        tmp += (ll)(v_cnt[i][k]*v_cnt[i][l])*(i|i)*(1<<9);
                        tmp += (ll)(v_cnt[i][k]*v_cnt[i][l])*(k|l);
                    }
                }
            }
        }
        ans += tmp;
    }
    for(int i = 0; i < N; i++){
        ans -= A[i];
    }
    ans /= 2;

    for(int i = 0; i < (1<<9); i++){
        for(int j = i+1; j < (1<<9); j++){
            ll cnt_i = v[i].size();            
            ll cnt_j = v[j].size();
            if((i^j) < lx){
                ans += (cnt_i*cnt_j)*(i|j)*(1<<9);
                for(int k = 0; k < 9; k++){
                    ll cnt_ok = cnt_i*cnt[j][k]+cnt_j*cnt[i][k]-cnt[j][k]*cnt[i][k];
                    ans += (1<<k)*cnt_ok;
                }
            }
            if((i^j) == lx){
                if(cnt_i*cnt_j < th){
                    for(int k : v[i]){
                        for(int l : v[j]){
                            if((k^l) < rx){
                                ans += (i|j)*(1<<9);
                                ans += (k|l);
                            }
                        }
                    }
                }else{
                    for(int k = 0; k < (1<<9); k++){
                        for(int l = 0; l < (1<<9); l++){
                            if((k^l) < rx){
                                ans += (ll)(v_cnt[i][k]*v_cnt[j][l])*(i|j)*(1<<9);
                                ans += (ll)(v_cnt[i][k]*v_cnt[j][l])*(k|l);
                            }
                        }
                    }
                }
            }
        }
    }
    
    cout << ans << endl;
}
0