結果

問題 No.578 3 x N グリッド上のサイクルのサイズ(easy)
ユーザー Ryuhei MoriRyuhei Mori
提出日時 2017-06-07 12:25:47
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,468 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 30,324 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 18:56:38
合計ジャッジ時間 1,467 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 1 ms
4,348 KB
testcase_37 AC 1 ms
4,348 KB
testcase_38 AC 1 ms
4,348 KB
testcase_39 AC 1 ms
4,348 KB
testcase_40 AC 1 ms
4,348 KB
testcase_41 AC 1 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 1 ms
4,348 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 1 ms
4,348 KB
testcase_46 AC 1 ms
4,348 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 1 ms
4,348 KB
testcase_49 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int mod = 1000000007;

int tmp[2][10][10];

const int T[10][10] = {
{1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 0, 0, 0, 1, 0, 1},
{0, 1, 1, 1, 1, 1, 0, 0, 0, 1},
{0, 1, 1, 1, 1, 1, 1, 0, 1, 1},
{0, 0, 1, 1, 1, 1, 0, 0, 0, 1},
{0, 0, 1, 1, 1, 1, 1, 0, 0, 1},
{0, 0, 0, 1, 0, 1, 1, 1, 0, 1},
{0, 0, 0, 1, 0, 0, 0, 1, 0, 0},
{0, 1, 0, 0, 0, 0, 1, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
};

const int TT[10][10] = {
{0, 3, 4, 5, 3, 4, 3, 6, 0, 0},
{0, 2, 3, 4, 0, 0, 0, 5, 0, 1},
{0, 3, 2, 3, 3, 4, 0, 0, 0, 2},
{0, 4, 3, 2, 4, 3, 4, 0, 5, 3},
{0, 0, 3, 4, 2, 3, 0, 0, 0, 1},
{0, 0, 4, 3, 3, 2, 3, 0, 0, 2},
{0, 0, 0, 4, 0, 3, 2, 5, 0, 1},
{0, 0, 0, 3, 0, 0, 0, 4, 0, 0},
{0, 3, 0, 0, 0, 0, 3, 0, 4, 2},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
};

int Ti[1000001][10][10];

void mult(const int A[10][10], const int B[10][10], int C[10][10]){
  int i, j, k;
  for(i=0;i<10;i++){
    for(j=0;j<10;j++){
      long long int tmp = 0;
      for(k=0;k<10;k++){
        tmp = (tmp + (long long int) A[i][k] * B[k][j]) % mod;
      }
      C[i][j] = tmp;
    }
  }
}

int main(){
  int i, j, ans;
  int n;
  scanf("%d", &n);

  for(i=0;i<10;i++){
    for(j=0;j<10;j++){
      Ti[0][i][j] = i == j;
    }
  }

  for(i=0;i<n;i++){
    mult(Ti[i], T, Ti[i+1]);
  }

  ans = 0;
  for(i=0;i<=n;i++){
    mult(Ti[i], TT, tmp[0]);
    mult(tmp[0], Ti[n-i], tmp[1]);
    ans += tmp[1][0][9];
    if(ans >= mod) ans -= mod;
  }

  printf("%d\n", ans);
  return 0;
}
0