結果
| 問題 |
No.1751 Fortune Nim
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2021-11-26 15:32:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 1,613 bytes |
| コンパイル時間 | 230 ms |
| コンパイル使用メモリ | 42,880 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-29 12:10:04 |
| 合計ジャッジ時間 | 2,937 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 1751.cc: No.1751 Fortune Nim - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 200000;
const int INF = 1 << 30;
const int MOD = 998244353;
/* typedef */
typedef long long ll;
template<const int MOD>
struct MI {
int v;
MI(): v() {}
MI(int _v): v(_v % MOD) {}
MI(long long _v): v(_v % MOD) {}
MI operator+(const MI m) const { return MI(v + m.v); }
MI operator-(const MI m) const { return MI(v + MOD - m.v); }
MI operator*(const MI m) const { return MI((long long)v * m.v); }
MI &operator+=(const MI m) { return (*this = *this + m); }
MI &operator-=(const MI m) { return (*this = *this - m); }
MI &operator*=(const MI m) { return (*this = *this * m); }
MI pow(long long n) const { // a^n % MOD
MI pm = 1, a = *this;
while (n > 0) {
if (n & 1) pm *= a;
a *= a;
n >>= 1;
}
return pm;
}
MI inv() const { return pow(MOD - 2); }
MI operator/(const MI m) const { return *this * m.inv(); }
MI &operator/=(const MI m) { return (*this = *this / m); }
};
typedef MI<MOD> mi;
/* global variables */
int as[MAX_N];
/* subroutines */
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", as + i);
int x = 0;
ll t = 0;
for (int i = 0; i < n; i++) {
x ^= as[i];
t += as[i];
}
if (x != 0) {
int mina = INF;
for (int i = 0; i < n; i++)
mina = min(mina, (x ^ as[i]) - as[i]);
t += mina + 1;
}
mi z = (mi(1) - (mi(0) - mi(1) / 3).pow(t)) / 2;
printf("%d\n", z.v);
return 0;
}
tnakao0123