結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
80,872 KB
testcase_01 AC 43 ms
80,888 KB
testcase_02 AC 43 ms
80,944 KB
testcase_03 AC 55 ms
80,948 KB
testcase_04 AC 57 ms
80,940 KB
testcase_05 AC 57 ms
80,960 KB
testcase_06 AC 52 ms
81,168 KB
testcase_07 AC 50 ms
81,184 KB
testcase_08 AC 51 ms
80,948 KB
testcase_09 AC 53 ms
80,872 KB
testcase_10 AC 111 ms
80,956 KB
testcase_11 AC 115 ms
80,936 KB
testcase_12 AC 177 ms
81,432 KB
testcase_13 AC 172 ms
81,044 KB
testcase_14 AC 162 ms
81,272 KB
testcase_15 AC 759 ms
81,740 KB
testcase_16 AC 674 ms
81,804 KB
testcase_17 AC 644 ms
81,808 KB
testcase_18 AC 705 ms
81,676 KB
testcase_19 AC 644 ms
81,800 KB
testcase_20 AC 750 ms
81,956 KB
testcase_21 AC 753 ms
81,564 KB
testcase_22 AC 770 ms
81,676 KB
testcase_23 AC 631 ms
81,808 KB
testcase_24 AC 719 ms
81,820 KB
testcase_25 AC 569 ms
81,732 KB
testcase_26 AC 734 ms
81,816 KB
testcase_27 AC 43 ms
80,952 KB
testcase_28 AC 43 ms
80,896 KB
testcase_29 WA -
testcase_30 AC 156 ms
81,260 KB
testcase_31 AC 171 ms
81,168 KB
testcase_32 AC 369 ms
81,764 KB
権限があれば一括ダウンロードができます

ソースコード

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<long long>> sum(LOG, vector<long long>(1 << (LOG + 1), 0));
  vector<long long> 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