結果

問題 No.1189 Sum is XOR
ユーザー 0w10w1
提出日時 2020-11-16 17:51:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,949 bytes
コンパイル時間 2,315 ms
コンパイル使用メモリ 204,432 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 07:25:27
合計ジャッジ時間 4,911 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
4,380 KB
testcase_01 AC 24 ms
4,380 KB
testcase_02 AC 24 ms
4,380 KB
testcase_03 AC 9 ms
4,380 KB
testcase_04 AC 8 ms
4,376 KB
testcase_05 AC 12 ms
4,380 KB
testcase_06 AC 17 ms
4,376 KB
testcase_07 AC 9 ms
4,380 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 10 ms
4,380 KB
testcase_12 AC 23 ms
4,380 KB
testcase_13 AC 21 ms
4,376 KB
testcase_14 AC 15 ms
4,376 KB
testcase_15 AC 11 ms
4,380 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 AC 10 ms
4,380 KB
testcase_18 AC 13 ms
4,380 KB
testcase_19 AC 19 ms
4,380 KB
testcase_20 AC 19 ms
4,380 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 8 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<int m>
struct Mint {
  int v;
  Mint(int _v = 0) : v(_v) { v %= m; adjust(); }
  void adjust() { if (v < 0) v += m; if (v >= m) v -= m; assert(0 <= v && v < m); }
  Mint operator+() const { return *this; }
  Mint operator-() const { Mint r = Mint(0) - *this; return r.adjust(), r; }
  friend Mint operator+(Mint a, Mint b) { a.v += b.v; return a.adjust(), a; }
  Mint& operator+=(const Mint &b) { return v += b.v, adjust(), *this; }
  friend Mint operator-(Mint a, Mint b) { a.v -= b.v; return a.adjust(), a; }
  Mint& operator-=(const Mint &b) { return v -= b.v, adjust(), *this; }
  friend Mint operator*(Mint a, Mint b) { a.v = (int64_t) a.v * b.v % m; return a.adjust(), a; }
  friend Mint operator*(Mint a, int v) { return a * Mint(v); }
  friend Mint operator^(Mint a, int p) {
    int v = a.v;
    int r = 1;
    for (int i = p; i; i >>= 1) {
      if (i & 1) r = (int64_t) r * v % m;
      v = (int64_t) v * v % m;
    }
    return r;
  }
  friend Mint operator^(Mint a, Mint p) { return a^p.v; }
  friend Mint operator/(Mint a, Mint b) { return a * (Mint(b.v)^(m-2)); }
  friend ostream& operator<<(ostream &os, Mint a) { return os << a.v, os; }
};

int main() {
  ios::sync_with_stdio(false);

  const int M = 998244353;

  int N, K; {
    cin >> N >> K;
  }

  vector<int> A(N); {
    for (int i = 0; i < N; ++i) cin >> A[i];
  }

  if (K > 10) { cout << 0 << endl; return 0; }

  vector<int> acnt(1 << 10); {
    for (int a : A) ++acnt[a];
  }

  vector<vector<Mint<M>>> dp(11, vector<Mint<M>>(1 << 10)); {
    dp[0][0] = 1;
    for (int a = 1; a < 1 << 10; ++a) {
      for (int n = 9; ~n; --n) {
        for (int s = (1 << 10) - 1; ~s; --s) {
          if (s & a) continue;
          dp[n + 1][s | a] = dp[n + 1][s | a] + dp[n][s] * acnt[a];
        }
      }
    }
  }

  Mint<M> res; {
    for (int s = 1; s < 1 << 10; ++s) res = res + dp[K][s];
  }

  cout << res << endl;
}

0