結果

問題 No.1876 Xor of Sum
ユーザー tnakao0123
提出日時 2022-03-18 11:23:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 467 ms / 2,000 ms
コード長 718 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 58,232 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-02 14:19:47
合計ジャッジ時間 10,211 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1876.cc:  No.1876 Xor of Sum - yukicoder
 */

#include<cstdio>
#include<bitset>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 2000;
const int MAX_A = 2000;
const int MAX_M = MAX_N * MAX_A;

/* typedef */

/* global variables */

int as[MAX_N];
bitset<MAX_M+1> dp[2];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  int cur = 0, nxt = 1;
  dp[cur].set(0);

  for (int i = 0; i < n; i++) {
    dp[nxt] = dp[cur] ^ (dp[cur] << as[i]);
    swap(cur, nxt);
  }

  int sum = 0;
  for (int i = 0; i <= MAX_M; i++)
    sum ^= i * dp[cur].test(i);
  printf("%d\n", sum);
  return 0;
}
0