結果

問題 No.1751 Fortune Nim
ユーザー SSRSSSRS
提出日時 2021-11-19 22:19:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,421 bytes
コンパイル時間 1,570 ms
コンパイル使用メモリ 170,912 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 08:59:08
合計ジャッジ時間 4,669 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
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 AC 58 ms
4,380 KB
testcase_17 AC 48 ms
4,380 KB
testcase_18 AC 65 ms
4,376 KB
testcase_19 AC 45 ms
4,376 KB
testcase_20 AC 71 ms
4,376 KB
testcase_21 AC 54 ms
4,380 KB
testcase_22 AC 71 ms
4,376 KB
testcase_23 AC 61 ms
4,380 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 74 ms
4,380 KB
testcase_29 AC 73 ms
4,376 KB
testcase_30 AC 73 ms
4,376 KB
testcase_31 AC 73 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long modpow(long long a, long long b){
	long long ans = 1;
	while (b > 0){
		if (b % 2 == 1){
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		b /= 2;
	}
	return ans;
}
long long modinv(long long a){
	return modpow(a, MOD - 2);
}
vector<long long> mf = {1};
vector<long long> mfi = {1};
long long modfact(int n){
	if (mf.size() > n){
		return mf[n];
	} else {
		for (int i = mf.size(); i <= n; i++){
			long long next = mf.back() * i % MOD;
			mf.push_back(next);
			mfi.push_back(modinv(next));
		}
		return mf[n];
	}
}
long long modfactinv(int n){
	if (mfi.size() > n){
		return mfi[n];
	} else {
		return modinv(modfact(n));
	}
}
long long modbinom(int n, int k){
	if (n < 0 || k < 0 || k > n){
		return 0;
	} else {
		return modfact(n) * modfactinv(k) % MOD * modfactinv(n - k) % MOD;
	}
}
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  long long S = 0;
  int X = 0;
  for (int i = 0; i < N; i++){
    S += a[i];
    X ^= a[i];
  }
  long long cnt;
  if (X == 0){
    cnt = S;
  } else {
    cnt = 0;
    for (int i = 0; i < N; i++){
      if ((a[i] ^ X) < a[i]){
        cnt = max(cnt, S - a[i] + (a[i] ^ X) + 1);
      }
    }
  }
  long long r = (MOD - 1) * modinv(3) % MOD;
  long long ans = (1 + MOD - modpow(r, cnt)) * modinv(2) % MOD;
  cout << ans << endl;
}
0