結果
| 問題 |
No.569 3 x N グリッドのパスの数
|
| コンテスト | |
| ユーザー |
HIR180
|
| 提出日時 | 2017-09-08 23:55:27 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,995 bytes |
| コンパイル時間 | 1,287 ms |
| コンパイル使用メモリ | 158,600 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-07 12:22:38 |
| 合計ジャッジ時間 | 2,835 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 60 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
/*vector<P>vec[100005];
int cnt = 0;
#define mod 1000000007
ll modpow(ll x,ll n)
{
ll res=1;
while(n>0)
{
if(n&1) res=res*x%mod;
x=x*x%mod;
n>>=1;
}
return res;
}
int main(){
cin>>n; n%=mod;
ll x[15];
x[0]=1; for(int i=1;i<15;i++)x[i]=x[i-1]*1LL*n%mod;
ll ans = x[1]*(x[10]-15LL*x[8]+6LL*x[7]+50LL*x[6]-26LL*x[5]-39LL*x[4]+36LL*x[3]-4LL*x[2]-4LL*x[1]+1LL)%mod;
ll ans2 = (x[6]+2LL*x[5]-9LL*x[4]-5LL*x[3]+15LL*x[2]-8LL*x[1]+1LL)%mod;
ans2 *= (x[6]+2LL*x[5]-7LL*x[4]-3LL*x[3]+7LL*x[2]-4LL*x[1]+1LL)%mod; ans2%=mod;
cout<<(ans*modpow(ans2,mod-2)%mod+mod)%mod<<endl;
}*/
int main(){
ll a[12]={1, 8, 38, 184, 976, 5382, 29739, 163496, 896476, 4913258, 26932712, 147657866};
ll coef[12]={12, -54, 124, -133, -16, 175, -94, -69, 40, 12, -4, -1};
ll pat[12][12][65]={};
for(int i=0;i<12;i++) for(int j=0;j<12;j++){
if(i!=11){
if(i+1==j) pat[i][j][0] = 1LL;
}
else{
pat[i][j][0] = coef[11-j];
}
}
for(int k=0;k<64;k++){
for(int i=0;i<12;i++)for(int j=0;j<12;j++)for(int x=0;x<12;x++){
pat[i][j][k+1] = (pat[i][j][k+1]+pat[i][x][k]*pat[x][j][k])%mod;
}
}
ll n; cin>>n;
if(n<=11){cout<<a[n]<<endl;return 0;}
n-=11;
for(int k=0;k<64;k++){
if(!((n>>k)&1LL)) continue;
ll b[12]={};
for(int j=0;j<12;j++)for(int x=0;x<12;x++){
b[j] = (b[j]+pat[j][x][k]*a[x])%mod;
}
for(int j=0;j<12;j++) a[j]=b[j];
}
cout<<(a[11]%mod+mod)%mod<<endl;
}
HIR180