結果
| 問題 | 
                            No.2668 Trees on Graph Paper
                             | 
                    
| コンテスト | |
| ユーザー | 
                             chro_96
                         | 
                    
| 提出日時 | 2024-03-08 23:56:53 | 
| 言語 | C  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,520 ms / 3,000 ms | 
| コード長 | 1,159 bytes | 
| コンパイル時間 | 1,380 ms | 
| コンパイル使用メモリ | 30,592 KB | 
| 実行使用メモリ | 353,444 KB | 
| 最終ジャッジ日時 | 2024-09-29 20:57:29 | 
| 合計ジャッジ時間 | 23,162 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
ソースコード
#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;
}
            
            
            
        
            
chro_96