結果

問題 No.2668 Trees on Graph Paper
ユーザー 👑 chro_96chro_96
提出日時 2024-03-09 12:57:24
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1,474 ms / 3,000 ms
コード長 1,199 bytes
コンパイル時間 834 ms
コンパイル使用メモリ 30,464 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-09 12:57:44
合計ジャッジ時間 18,236 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 125 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 856 ms
6,676 KB
testcase_15 AC 1,336 ms
6,676 KB
testcase_16 AC 658 ms
6,676 KB
testcase_17 AC 66 ms
6,676 KB
testcase_18 AC 1,269 ms
6,676 KB
testcase_19 AC 1,065 ms
6,676 KB
testcase_20 AC 1,171 ms
6,676 KB
testcase_21 AC 1,126 ms
6,676 KB
testcase_22 AC 1,152 ms
6,676 KB
testcase_23 AC 737 ms
6,676 KB
testcase_24 AC 1,451 ms
6,676 KB
testcase_25 AC 1,454 ms
6,676 KB
testcase_26 AC 1,450 ms
6,676 KB
testcase_27 AC 1,474 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 1 ms
6,676 KB
testcase_30 AC 1 ms
6,676 KB
testcase_31 AC 1 ms
6,676 KB
testcase_32 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

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