QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#32483 | #874. Long Grid Covering | Froggygua | WA | 3ms | 3544kb | C++ | 1001b | 2022-05-20 16:52:39 | 2022-05-20 16:52:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll n;
struct Matrix{
int g[7][7];
Matrix(){memset(g,0,sizeof(g));}
friend Matrix operator * (const Matrix &a,const Matrix &b){
Matrix c;
for(int i=1;i<=6;++i){
for(int j=1;j<=6;++j){
for(int k=1;k<=6;++k){
c.g[i][j]=(c.g[i][j]+1LL*a.g[i][k]*b.g[k][j])%mod;
}
}
}
return c;
}
}e;
// [ dp[n] dp[n-1] dp[n-2] s[n-1] s[n-2] s[n-3] ]
Matrix mpow(Matrix a,ll b){
Matrix ans=e;
while(b){
if(b&1)ans=ans*a;
a=a*a;
b>>=1;
}
return ans;
}
void Solve(){
cin>>n;
Matrix s;
s.g[1][2]=s.g[2][3]=1;
s.g[4][5]=s.g[5][6]=1;
s.g[1][1]=1;
s.g[3][1]=1;
s.g[4][1]=2;
s.g[5][1]=4;
s.g[1][4]=1;
s.g[6][4]=1;
Matrix pre;
pre.g[1][1]=1;
Matrix ans=pre*mpow(s,n);
cout<<ans.g[1][1]<<'\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
for(int i=1;i<=6;++i)e.g[i][i]=1;
int T;
cin>>T;
while(T--)Solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 3544kb
input:
4 1 2 3 10
output:
1 3 10 6856
result:
wrong answer 4th numbers differ - expected: '8266', found: '6856'