結果

問題 No.2810 Have Another Go (Hard)
ユーザー chro_96chro_96
提出日時 2024-07-13 11:51:14
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1,426 ms / 3,000 ms
コード長 2,246 bytes
コンパイル時間 439 ms
コンパイル使用メモリ 31,616 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-13 11:52:08
合計ジャッジ時間 53,113 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1,401 ms
6,944 KB
testcase_02 AC 1,396 ms
6,944 KB
testcase_03 AC 1,400 ms
6,940 KB
testcase_04 AC 1,426 ms
6,940 KB
testcase_05 AC 1,399 ms
6,940 KB
testcase_06 AC 1,405 ms
6,944 KB
testcase_07 AC 1,399 ms
6,940 KB
testcase_08 AC 1,404 ms
6,944 KB
testcase_09 AC 1,398 ms
6,944 KB
testcase_10 AC 1,399 ms
6,940 KB
testcase_11 AC 9 ms
6,944 KB
testcase_12 AC 9 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 11 ms
6,940 KB
testcase_15 AC 8 ms
6,940 KB
testcase_16 AC 323 ms
6,944 KB
testcase_17 AC 1,231 ms
6,940 KB
testcase_18 AC 748 ms
6,944 KB
testcase_19 AC 1,171 ms
6,940 KB
testcase_20 AC 176 ms
6,940 KB
testcase_21 AC 429 ms
6,940 KB
testcase_22 AC 746 ms
6,940 KB
testcase_23 AC 546 ms
6,940 KB
testcase_24 AC 860 ms
6,944 KB
testcase_25 AC 1,328 ms
6,944 KB
testcase_26 AC 1,401 ms
6,944 KB
testcase_27 AC 1,397 ms
6,944 KB
testcase_28 AC 1,396 ms
6,940 KB
testcase_29 AC 1,398 ms
6,944 KB
testcase_30 AC 1,394 ms
6,940 KB
testcase_31 AC 1,410 ms
6,944 KB
testcase_32 AC 1,397 ms
6,944 KB
testcase_33 AC 1,394 ms
6,944 KB
testcase_34 AC 1,407 ms
6,940 KB
testcase_35 AC 1,398 ms
6,940 KB
testcase_36 AC 1,397 ms
6,940 KB
testcase_37 AC 1,394 ms
6,940 KB
testcase_38 AC 1,397 ms
6,940 KB
testcase_39 AC 1,394 ms
6,940 KB
testcase_40 AC 1,396 ms
6,944 KB
testcase_41 AC 1,416 ms
6,944 KB
testcase_42 AC 1,397 ms
6,940 KB
testcase_43 AC 1,400 ms
6,940 KB
testcase_44 AC 1,397 ms
6,944 KB
testcase_45 AC 1,399 ms
6,940 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 4 ms
6,940 KB
testcase_48 AC 6 ms
6,944 KB
testcase_49 AC 3 ms
6,940 KB
testcase_50 AC 4 ms
6,944 KB
testcase_51 AC 60 ms
6,944 KB
testcase_52 AC 33 ms
6,944 KB
testcase_53 AC 79 ms
6,940 KB
testcase_54 AC 92 ms
6,940 KB
testcase_55 AC 39 ms
6,944 KB
testcase_56 AC 88 ms
6,944 KB
testcase_57 AC 72 ms
6,940 KB
testcase_58 AC 65 ms
6,944 KB
testcase_59 AC 127 ms
6,944 KB
testcase_60 AC 85 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

void mul_matrix (long long a[][6], long long b[][6], long long ans[][6], long long mod_num) {
  for (int i = 0; i < 6; i++) {
    for (int j = 0; j < 6; j++) {
      ans[i][j] = 0LL;
      for (int k = 0; k < 6; k++) {
        ans[i][j] += a[i][k]*b[k][j];
        ans[i][j] %= mod_num;
      }
    }
  }
  return;
}

void power_matrix (long long a[][6], long long b, long long ans[][6], long long mod_num) {
  long long wk[6][6] = {};
  
  if (b <= 0LL) {
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 6; j++) {
        ans[i][j] = 0LL;
      }
      ans[i][i] = 1LL;
    }
    return;
  }
  
  if (b%2LL == 1LL) {
    power_matrix(a, b/2LL, ans, mod_num);
    mul_matrix(ans, ans, wk, mod_num);
    mul_matrix(a, wk, ans, mod_num);
    return;
  }
  
  power_matrix(a, b/2LL, wk, mod_num);
  mul_matrix(wk, wk, ans, mod_num);
  return;
}

int main () {
  long long n = 0LL;
  long long m = 0LL;
  int k = 0;
  int c[5000] = {};
  
  int res = 0;
  
  long long ans[5000] = {};
  long long mod_num = 998244353LL;
  
  long long total = 0LL;
  
  long long wk1[6][6] = {};
  long long wk2[6][6] = {};
  long long wk_p[6][6] = {};
  long long wk3[6][6] = {};
  
  res = scanf("%lld", &n);
  res = scanf("%lld", &m);
  res = scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    res = scanf("%d", c+i);
  }
  
  for (int i = 0; i < 5; i++) {
    wk1[i+1][i] = 1LL;
  }
  for (int i = 0; i < 6; i++) {
    wk1[0][i] = 1LL;
  }
  
  power_matrix(wk1, n*m, wk2, mod_num);
    
  for (int i = 0; i < 6; i++) {
    total += wk2[0][i];
  }
  total %= mod_num;
  
  power_matrix(wk1, n, wk2, mod_num);
  
  for (int i = 0; i < 5; i++) {
    wk3[i+1][i+1] = 1LL;
  }
  
  mul_matrix(wk2, wk3, wk_p, mod_num);
  power_matrix(wk_p, m-1LL, wk2, mod_num);
  mul_matrix(wk3, wk2, wk_p, mod_num);
    
  for (int i = 0; i < k; i++) {
    long long wk4[6][6] = {};
    power_matrix(wk1, (long long)c[i], wk3, mod_num);
    mul_matrix(wk_p, wk3, wk4, mod_num);
    power_matrix(wk1, n-((long long)(c[i]+1)), wk3, mod_num);
    mul_matrix(wk3, wk4, wk2, mod_num);
    for (int j = 0; j < 6; j++) {
      ans[i] += wk2[j][0]*((long long)(6-j));
    }
    printf("%lld\n", (total+mod_num-ans[i]%mod_num)%mod_num);
  }
  
  return 0;
}
0