結果

問題 No.2668 Trees on Graph Paper
ユーザー 👑 chro_96chro_96
提出日時 2024-03-08 23:56:53
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1,421 ms / 3,000 ms
コード長 1,159 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 31,104 KB
実行使用メモリ 353,460 KB
最終ジャッジ日時 2024-03-08 23:57:13
合計ジャッジ時間 18,974 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
353,460 KB
testcase_01 AC 81 ms
353,460 KB
testcase_02 AC 82 ms
353,460 KB
testcase_03 AC 197 ms
353,460 KB
testcase_04 AC 81 ms
353,460 KB
testcase_05 AC 103 ms
353,460 KB
testcase_06 AC 82 ms
353,460 KB
testcase_07 AC 81 ms
353,460 KB
testcase_08 AC 89 ms
353,460 KB
testcase_09 AC 82 ms
353,460 KB
testcase_10 AC 83 ms
353,460 KB
testcase_11 AC 81 ms
353,460 KB
testcase_12 AC 89 ms
353,460 KB
testcase_13 AC 81 ms
353,460 KB
testcase_14 AC 899 ms
353,460 KB
testcase_15 AC 1,305 ms
353,460 KB
testcase_16 AC 685 ms
353,460 KB
testcase_17 AC 150 ms
353,460 KB
testcase_18 AC 1,249 ms
353,460 KB
testcase_19 AC 1,060 ms
353,460 KB
testcase_20 AC 1,172 ms
353,460 KB
testcase_21 AC 1,127 ms
353,460 KB
testcase_22 AC 1,142 ms
353,460 KB
testcase_23 AC 746 ms
353,460 KB
testcase_24 AC 1,419 ms
353,460 KB
testcase_25 AC 1,419 ms
353,460 KB
testcase_26 AC 1,421 ms
353,460 KB
testcase_27 AC 1,420 ms
353,460 KB
testcase_28 AC 80 ms
353,460 KB
testcase_29 AC 89 ms
353,460 KB
testcase_30 AC 81 ms
353,460 KB
testcase_31 AC 80 ms
353,460 KB
testcase_32 AC 81 ms
353,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main () {
  int n = 0;
  long long m = 0LL;
  
  int res = 0;
  
  long long ans = 1LL;
  int acc[10000000][3][3] = {};
  
  res = scanf("%d", &n);
  res = scanf("%lld", &m);
  
  acc[0][0][0] = 1;
  acc[0][0][1] = 2;
  acc[0][0][2] = 0;
  acc[0][1][0] = 1;
  acc[0][1][1] = 1;
  acc[0][1][2] = 2;
  acc[0][2][0] = 1;
  acc[0][2][1] = 1;
  acc[0][2][2] = 1;
  for (int i = 1; i < 2*n; i++) {
    long long tmp1[3][3] = { { 1LL, (long long)(i+2), 0LL }, { 1LL, 1LL, (long long)(i+2) }, { 1LL, 1LL, 1LL} };
    long long tmp2[3][3] = {};
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        for (int l = 0; l < 3; l++) {
          tmp2[j][k] += tmp1[j][l]*((long long)acc[i-1][l][k]);
        }
        acc[i][j][k] = (int)(tmp2[j][k]%m);
      }
    }
  }
  
  for (int i = 0; i < 2*n-1; i++) {
    ans *= (long long)(i+1);
    ans %= m;
  }
  
  for (int i = 2; i < n; i++) {
    long long mul = 0LL;
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        mul += (long long)acc[2*(i-2)][j][k];
      }
    }
    ans *= mul%m;
    ans %= m;
  }
  
  printf("%lld\n", ans%m);
  return 0;
}
0