結果

問題 No.1751 Fortune Nim
コンテスト
ユーザー 👑 Nachia
提出日時 2026-11-23 05:47:57
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 12 ms / 2,000 ms
+ 824µs
コード長 1,201 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,369 ms
コンパイル使用メモリ 219,424 KB
実行使用メモリ 9,908 KB
最終ジャッジ日時 2026-11-23 05:48:02
合計ジャッジ時間 4,754 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:10:12: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' [-Wc++20-extensions]
   10 | bool chmax(auto& a, auto b) { return a < b && (a = b, true); }
      |            ^~~~
main.cpp:10:21: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' [-Wc++20-extensions]
   10 | bool chmax(auto& a, auto b) { return a < b && (a = b, true); }
      |                     ^~~~
main.cpp:11:12: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' [-Wc++20-extensions]
   11 | bool chmin(auto& a, auto b) { return b < a && (a = b, true); }
      |            ^~~~
main.cpp:11:21: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' [-Wc++20-extensions]
   11 | bool chmin(auto& a, auto b) { return b < a && (a = b, true); }
      |                     ^~~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

#include <cassert>
using namespace std;
using ll = long long;
const ll INF = 1ll << 26;
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
template <class T>
using V = vector<T>;
bool chmax(auto& a, auto b) { return a < b && (a = b, true); }
bool chmin(auto& a, auto b) { return b < a && (a = b, true); }

ll powm(ll a, ll i, ll m){
  a %= m;
  if(i == 0) return 1 % m;
  ll r = powm(a*a%m, i/2, m);
  if(i%2) r = r * a % m;
  return r;
}

const ll MOD = 998244353;

ll invm(ll a){
  return powm(a, MOD-2, MOD);
}

void testcase() {
  ll N; cin >> N;
  V<ll> A(N); REP(i,N) cin >> A[i];
  ll xorA = 0, sumA = 0;
  for(auto a : A) xorA ^= a;
  for(auto a : A) sumA += a;
  if(xorA == 0){
    ll ans = (MOD - powm(invm(3), sumA, MOD)) % MOD;
    ans = (ans + 1) * invm(2) % MOD;
    cout << ans << "\n";
  }
  else {
    ll maxv = 0;
    for(ll a : A){
      ll tg = xorA ^ a;
      if(tg < a) chmax(maxv, a - tg);
    }
    ll ans = (powm(invm(3), sumA - maxv + 1, MOD)) % MOD;
    ans = (ans + 1) * invm(2) % MOD;
    cout << ans << "\n";
  }
  // cout << xorA << " " << sumA << endl;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    testcase();
    return 0;
}
0