結果

問題 No.1751 Fortune Nim
ユーザー KudeKude
提出日時 2021-11-19 23:09:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,306 bytes
コンパイル時間 2,559 ms
コンパイル使用メモリ 225,376 KB
実行使用メモリ 12,064 KB
最終ジャッジ日時 2023-08-30 10:18:33
合計ジャッジ時間 11,355 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
11,408 KB
testcase_01 AC 15 ms
11,196 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) { a = max(a, b); }
template<class T> void chmin(T& a, const T& b) { a = min(a, b); }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;
constexpr int FACT_SIZE = 1000000;
mint Fact[FACT_SIZE + 1];
mint iFact[FACT_SIZE + 1];
const auto fact_init = [] {
    Fact[0] = mint::raw(1);
    for(int i = 1; i <= FACT_SIZE; ++i) {
        Fact[i] = Fact[i-1] * i;
    }
    iFact[FACT_SIZE] = Fact[FACT_SIZE].inv();
    for(int i = FACT_SIZE; i; --i) {
        iFact[i-1] = iFact[i] * i;
    }
    return false;
}();

mint comb(int n, int k) {
    if (k == 0) return mint::raw(1);
    assert(n >= 0 && k >= 0);
    if (k > n) return mint::raw(0);
    return Fact[n] * iFact[n - k] * iFact[k];
}

mint icomb(int n, int k) {
    return iFact[n] * Fact[n - k] * Fact[k];
}

mint fact(int n) {return Fact[n];}
mint perm(int n, int k) {
    assert(0 <= n);
    return Fact[n] * iFact[n - k];
}

const mint f13 = mint(1) / 3, f23 = mint(2) / 3;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI a(n);
  rep(i, n) cin >> a[i];
  int x = 0;
  for(int y: a) x ^= y;
  int cnt = 0;
  if (x != 0) {
    cnt++;
    int mn = 1001001001;
    int imn = -1;
    rep(i, n) {
      if ((a[i] ^ x) < a[i]) {
        int diff = __builtin_popcount(a[i] ^ x) - __builtin_popcount(a[i]);
        if (diff < mn) {
          mn = diff;
          imn = i;
        }
      }
    }
    a[imn] ^= x;
  }
  rep(i, n) cnt += __builtin_popcount(a[i]);
  mint c0, c1;
  rep(i, cnt) {
    if (i % 2 == 0) {
      c0 += comb(cnt, i) * f13.pow(i) * f23.pow(cnt - i);
    } else {
      c1 += comb(cnt, i) * f13.pow(i) * f23.pow(cnt - i);
    }
  }
  mint ans;
  if (cnt % 2 == 0) {
    ans = c1;
  } else {
    ans = c0;
  }
  cout << ans.val() << endl;
}
0