結果

問題 No.1751 Fortune Nim
ユーザー SSRSSSRS
提出日時 2021-11-19 22:20:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,421 bytes
コンパイル時間 1,689 ms
コンパイル使用メモリ 170,388 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-30 09:01:26
合計ジャッジ時間 5,136 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,388 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 54 ms
4,380 KB
testcase_09 AC 51 ms
4,376 KB
testcase_10 AC 44 ms
4,380 KB
testcase_11 AC 65 ms
4,380 KB
testcase_12 AC 40 ms
4,376 KB
testcase_13 AC 66 ms
4,376 KB
testcase_14 AC 49 ms
4,376 KB
testcase_15 AC 49 ms
4,380 KB
testcase_16 AC 58 ms
4,384 KB
testcase_17 AC 49 ms
4,380 KB
testcase_18 AC 66 ms
4,380 KB
testcase_19 AC 46 ms
4,376 KB
testcase_20 AC 71 ms
4,384 KB
testcase_21 AC 54 ms
4,380 KB
testcase_22 AC 71 ms
4,380 KB
testcase_23 AC 62 ms
4,380 KB
testcase_24 AC 75 ms
4,380 KB
testcase_25 AC 75 ms
4,380 KB
testcase_26 AC 74 ms
4,380 KB
testcase_27 AC 73 ms
4,376 KB
testcase_28 AC 73 ms
4,384 KB
testcase_29 AC 73 ms
4,376 KB
testcase_30 AC 73 ms
4,376 KB
testcase_31 AC 74 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 = S;
    for (int i = 0; i < N; i++){
      if ((a[i] ^ X) < a[i]){
        cnt = min(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