結果

問題 No.541 3 x N グリッド上のサイクルの個数
ユーザー beetbeet
提出日時 2017-06-30 23:42:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,784 bytes
コンパイル時間 1,430 ms
コンパイル使用メモリ 167,740 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 07:11:37
合計ジャッジ時間 3,039 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long

int MOD=1000000007LL; //<- alert!!!
typedef vector<int> arr;
typedef vector<arr> mat;
inline arr mul(mat a,arr& b,int mod){
  arr res(b.size(),0);
  for(int i=0;i<(int)b.size();i++)
    for(int j=0;j<(int)a[i].size();j++)
      (res[i]+=a[i][j]*b[j])%=mod;
  return res;
}
inline mat mul(mat& a,mat& b,int mod){
  mat res(a.size(),arr(b[0].size(),0));
  for(int i=0;i<(int)a.size();i++)
    for(int j=0;j<(int)b[0].size();j++)
      for(int k=0;k<(int)b.size();k++)
	(res[i][j]+=a[i][k]*b[k][j])%=mod;
  return res;
}
mat base;
inline mat mat_pow(mat a,int n,int mod){
  if(base.empty()){
    base=mat(a);
    for(int i=0;i<(int)a.size();i++)
      for(int j=0;j<(int)a[i].size();j++)
	base[i][j]=(i==j);
  }
  mat res(base);
  while(n){
    if(n&1) res=mul(a,res,mod);
    a=mul(a,a,mod);
    n>>=1;
  }
  return res;
}
void s(arr &a,int a0,int a1,int a2,int a3,int a4,
       int a5,int a6,int a7,int a8,int a9){
  a[0]=a0;
  a[1]=a1;
  a[2]=a2;
  a[3]=a3;
  a[4]=a4;
  a[5]=a5;
  a[6]=a6;
  a[7]=a7;
  a[8]=a8;
  a[9]=a9;
}
signed main(){
  int n;
  cin>>n;
  arr a(10,0);
  a[8]=1;
  mat m(10,arr(10,0));
  s(m[0],1,0,0,0,0,0,0,0,0,0);
  s(m[1],1,1,0,1,0,0,0,1,0,1);
  s(m[2],1,0,1,1,0,0,1,1,0,0);
  s(m[3],1,1,1,1,0,0,1,1,0,0);
  s(m[4],1,0,0,0,1,0,1,1,0,1);
  s(m[5],1,1,0,0,1,1,0,0,0,0);
  s(m[6],1,0,1,1,1,0,1,1,0,0);
  s(m[7],1,1,1,1,1,1,1,1,0,0);
  s(m[8],0,1,1,1,1,0,1,1,1,1);
  s(m[9],0,0,0,0,0,0,0,1,0,1);
  for(int i=0;i<10;i++)
    for(int j=i+1;j<10;j++)
      swap(m[i][j],m[j][i]);
  m=mat_pow(m,n+1,MOD);
  /*
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++) cout<<m[i][j];
    cout<<endl;
  }
  */
  a=mul(m,a,MOD);
  //for(int i=0;i<10;i++) cout<<a[i]<<endl;
  cout<<a[0]<<endl;
  return 0;
}
0