結果

問題 No.578 3 x N グリッド上のサイクルのサイズ(easy)
ユーザー Ryuhei MoriRyuhei Mori
提出日時 2017-06-01 18:05:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,751 bytes
コンパイル時間 1,304 ms
コンパイル使用メモリ 24,096 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-23 18:55:51
合計ジャッジ時間 1,542 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,348 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:69:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   69 |   scanf("%lld", &n);
      |   ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

#define M 12

const int mod = 1000000007;

int dp[2][M][M];

const int T[M][M] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   -4},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   -4},
{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,   39},
{0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,   -56},
{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,  -62},
{0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,  386},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,  -753},
{0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,  884},
{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, -685},
{0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,  342},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,  -102},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,   16},
};

const int s[M] = {
  32, 314, 2264, 14204, 83356, 470774, 2591384, 13998084, 74524728, 392208042, 44776278, 577440486
};


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

void modpow(long long int n, int A[2][M][M]){
  int i, j;
  int tmp[2][M][M];
  int b = 0;
  int c = 0;
  for(i=0;i<M;i++){
    for(j=0;j<M;j++){
      tmp[0][i][j] = i == j;
    }
  }

  while(n){
    if(n&1) mult(tmp[b], A[c], tmp[b^1]), b^=1;
    mult(A[c], A[c], A[c^1]), c^=1;
    n /= 2;
  }

  for(i=0;i<M;i++){
    for(j=0;j<M;j++){
      A[0][i][j] = tmp[b][i][j];
    }
  }
}

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

  for(i=0;i<M;i++){
    for(j=0;j<M;j++){
      dp[0][i][j] = T[i][j];
    }
  }

  if(n <= M){
    printf("%d\n", s[n-1]);
    return 0;
  }
  modpow(n-M, dp);
  ans = 0;
  for(i=0;i<M;i++){
    ans = (ans + (long long) s[i] * dp[0][i][M-1]) % mod;
  }

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