結果

問題 No.2810 Have Another Go (Hard)
ユーザー chro_96chro_96
提出日時 2024-07-13 11:36:04
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2,873 ms / 3,000 ms
コード長 2,216 bytes
コンパイル時間 898 ms
コンパイル使用メモリ 31,004 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-13 11:37:45
合計ジャッジ時間 97,544 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2,022 ms
6,944 KB
testcase_02 AC 2,033 ms
6,944 KB
testcase_03 AC 1,994 ms
6,940 KB
testcase_04 AC 1,989 ms
6,944 KB
testcase_05 AC 1,972 ms
6,944 KB
testcase_06 AC 1,985 ms
6,940 KB
testcase_07 AC 2,031 ms
6,940 KB
testcase_08 AC 1,993 ms
6,940 KB
testcase_09 AC 2,005 ms
6,944 KB
testcase_10 AC 2,014 ms
6,944 KB
testcase_11 AC 13 ms
6,940 KB
testcase_12 AC 12 ms
6,940 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 AC 15 ms
6,940 KB
testcase_15 AC 11 ms
6,944 KB
testcase_16 AC 576 ms
6,944 KB
testcase_17 AC 2,451 ms
6,940 KB
testcase_18 AC 1,476 ms
6,944 KB
testcase_19 AC 2,258 ms
6,940 KB
testcase_20 AC 336 ms
6,940 KB
testcase_21 AC 799 ms
6,944 KB
testcase_22 AC 1,387 ms
6,944 KB
testcase_23 AC 1,027 ms
6,944 KB
testcase_24 AC 1,710 ms
6,944 KB
testcase_25 AC 2,529 ms
6,940 KB
testcase_26 AC 2,741 ms
6,944 KB
testcase_27 AC 2,722 ms
6,940 KB
testcase_28 AC 2,739 ms
6,944 KB
testcase_29 AC 2,724 ms
6,944 KB
testcase_30 AC 2,733 ms
6,940 KB
testcase_31 AC 2,707 ms
6,940 KB
testcase_32 AC 2,721 ms
6,944 KB
testcase_33 AC 2,849 ms
6,940 KB
testcase_34 AC 2,873 ms
6,940 KB
testcase_35 AC 2,723 ms
6,940 KB
testcase_36 AC 2,701 ms
6,940 KB
testcase_37 AC 2,692 ms
6,944 KB
testcase_38 AC 2,705 ms
6,944 KB
testcase_39 AC 2,766 ms
6,944 KB
testcase_40 AC 2,732 ms
6,944 KB
testcase_41 AC 2,740 ms
6,940 KB
testcase_42 AC 2,746 ms
6,944 KB
testcase_43 AC 2,705 ms
6,940 KB
testcase_44 AC 2,742 ms
6,940 KB
testcase_45 AC 2,739 ms
6,944 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 6 ms
6,940 KB
testcase_48 AC 11 ms
6,944 KB
testcase_49 AC 5 ms
6,944 KB
testcase_50 AC 7 ms
6,940 KB
testcase_51 AC 339 ms
6,944 KB
testcase_52 AC 210 ms
6,944 KB
testcase_53 AC 507 ms
6,940 KB
testcase_54 AC 632 ms
6,940 KB
testcase_55 AC 254 ms
6,944 KB
testcase_56 AC 573 ms
6,940 KB
testcase_57 AC 421 ms
6,944 KB
testcase_58 AC 339 ms
6,940 KB
testcase_59 AC 796 ms
6,940 KB
testcase_60 AC 488 ms
6,940 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] = {};
  
  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;
  
  for (int i = 0; i < k; i++) {
    long long wk3[6][6] = {};
    long long wk4[6][6] = {};
    for (int j = 0; j < 5; j++) {
      wk3[j+1][j+1] = 1LL;
    }
    power_matrix(wk1, n, wk2, mod_num);
    mul_matrix(wk2, wk3, wk4, mod_num);
    power_matrix(wk4, m-1LL, wk2, mod_num);
    mul_matrix(wk3, wk2, wk4, mod_num);
    power_matrix(wk1, (long long)c[i], wk2, mod_num);
    mul_matrix(wk4, wk2, wk3, mod_num);
    power_matrix(wk1, n-((long long)(c[i]+1)), wk2, mod_num);
    mul_matrix(wk2, wk3, wk4, mod_num);
    for (int j = 0; j < 6; j++) {
      ans[i] += wk4[j][0]*((long long)(6-j));
    }
    printf("%lld\n", (total+mod_num-ans[i]%mod_num)%mod_num);
  }
  
  return 0;
}
0