結果

問題 No.2514 Twelvefold Way Returns
ユーザー SSRSSSRS
提出日時 2023-10-20 22:37:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 3,000 ms
コード長 1,826 bytes
コンパイル時間 2,239 ms
コンパイル使用メモリ 208,620 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 22:37:15
合計ジャッジ時間 5,105 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 12 ms
4,348 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 52 ms
4,348 KB
testcase_05 AC 44 ms
4,348 KB
testcase_06 AC 37 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 27 ms
4,348 KB
testcase_09 AC 29 ms
4,348 KB
testcase_10 AC 65 ms
4,348 KB
testcase_11 AC 5 ms
4,348 KB
testcase_12 AC 15 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 13 ms
4,348 KB
testcase_15 AC 25 ms
4,348 KB
testcase_16 AC 61 ms
4,348 KB
testcase_17 AC 36 ms
4,348 KB
testcase_18 AC 60 ms
4,348 KB
testcase_19 AC 62 ms
4,348 KB
testcase_20 AC 67 ms
4,348 KB
testcase_21 AC 63 ms
4,348 KB
testcase_22 AC 63 ms
4,348 KB
testcase_23 AC 22 ms
4,348 KB
testcase_24 AC 63 ms
4,348 KB
testcase_25 AC 32 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 64 ms
4,348 KB
testcase_28 AC 17 ms
4,348 KB
testcase_29 AC 16 ms
4,348 KB
testcase_30 AC 12 ms
4,348 KB
testcase_31 AC 18 ms
4,348 KB
testcase_32 AC 10 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 11 ms
4,348 KB
testcase_35 AC 49 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 60 ms
4,348 KB
testcase_39 AC 69 ms
4,348 KB
testcase_40 AC 61 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const long long ONE_THIRD = 332748118;
array<long long, 3> operator +(array<long long, 3> A, array<long long, 3> B){
  array<long long, 3> C = {};
  for (int i = 0; i < 3; i++){
    C[i] = (A[i] + B[i]) % MOD;
  }
  return C;
}
array<long long, 3> operator *(array<long long, 3> A, long long k){
  for (int i = 0; i < 3; i++){
    A[i] *= k;
    A[i] %= MOD;
  }
  return A;
}
array<long long, 3> operator *(array<long long, 3> A, array<long long, 3> B){
  array<long long, 3> C = {};
  for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++){
      int k = (i + j) % 3;
      C[k] += A[i] * B[j];
      C[k] %= MOD;
    }
  }
  return C;
}
array<long long, 3> pow(array<long long, 3> A, int N){
  array<long long, 3> ans = {1, 0, 0};
  while (N > 0){
    if (N % 2 == 1){
      ans = ans * A;
    }
    A = A * A;
    N /= 2;
  }
  return ans;
}
array<long long, 3> shift(array<long long, 3> A, int N){
  array<long long, 3> B = {};
  for (int i = 0; i < 3; i++){
    B[(i + N) % 3] = A[i];
  }
  return B;
}
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<long long>> binom(M + 1, vector<long long>(M + 1, 0));
  for (int i = 0; i <= M; i++){
    binom[i][0] = 1;
    for (int j = 1; j < i; j++){
      binom[i][j] = (binom[i - 1][j - 1] + binom[i - 1][j]) % MOD;
    }
    binom[i][i] = 1;
  }
  array<long long, 3> ans = {};
  for (int i = 0; i <= M; i++){
    for (int j = 0; i + j <= M; j++){
      int k = M - i - j;
      long long c = binom[M][i] * binom[M - i][j] % MOD;
      array<long long, 3> x = {i, j, k};
      ans = ans + shift(pow(x, N), j * 2 + k) * c;
    }
  }
  long long ans2 = (ans[0] - ans[1] + MOD) % MOD;
  for (int i = 0; i < M; i++){
    ans2 *= ONE_THIRD;
    ans2 %= MOD;
  }
  cout << ans2 << endl;
}
0