結果

問題 No.1240 Or Sum of Xor Pair
ユーザー SSRSSSRS
提出日時 2020-09-25 22:13:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,356 bytes
コンパイル時間 2,149 ms
コンパイル使用メモリ 205,492 KB
実行使用メモリ 43,188 KB
最終ジャッジ日時 2023-09-10 15:27:56
合計ジャッジ時間 14,050 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
42,172 KB
testcase_01 AC 33 ms
42,100 KB
testcase_02 AC 34 ms
42,120 KB
testcase_03 AC 45 ms
42,064 KB
testcase_04 AC 47 ms
42,108 KB
testcase_05 AC 47 ms
42,164 KB
testcase_06 AC 43 ms
42,256 KB
testcase_07 AC 42 ms
42,052 KB
testcase_08 AC 41 ms
42,116 KB
testcase_09 AC 43 ms
42,176 KB
testcase_10 AC 102 ms
42,120 KB
testcase_11 AC 103 ms
42,084 KB
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 34 ms
42,116 KB
testcase_28 AC 34 ms
42,220 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int LOG = 18;
int main(){
  int N, X;
  cin >> N >> X;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<vector<int>> sum(LOG, vector<int>(1 << (LOG + 1), 0));
  vector<int> cnt(1 << (LOG + 1), 0);
  for (int i = 0; i < N; i++){
    int v = 1;
    for (int j = 0; j <= LOG; j++){
      for (int k = 0; k < LOG; k++){
        if (A[i] >> k & 1){
          sum[k][v]++;
        }
      } 
      cnt[v]++;
      if (j < LOG){
        if (A[i] >> (LOG - 1 - j) & 1){
          v = v * 2 + 1;
        } else {
          v = v * 2;
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < N; i++){
    int v = 1;
    vector<int> id;
    for (int j = LOG - 1; j >= 0; j--){
      if (A[i] >> j & 1){
        if (X >> j & 1){
          id.push_back(v * 2 + 1);
          v = v * 2;
        } else {
          v = v * 2 + 1;
        }
      } else {
        if (X >> j & 1){
          id.push_back(v * 2);
          v = v * 2 + 1;
        } else {
          v = v * 2;
        }
      }
    }
    for (int x : id){
      for (int j = 0; j < LOG; j++){
        if (A[i] >> j & 1){
          ans += cnt[x] << j;
        } else {
          ans += sum[j][x] << j;
        }
      }
    }
  }
  for (int i = 0; i < N; i++){
    ans -= A[i];
  }
  cout << ans / 2 << endl;
}
0