QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#764272 | #9479. And DNA | mhb2010 | WA | 0ms | 3656kb | C++14 | 879b | 2024-11-20 08:24:35 | 2024-11-20 08:24:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
void ts(){cout<<"IAKIOI"<<endl;}
int n, m;
const int mod=998244353;
struct matrix{
int a[3][3]={};
}f, g;
matrix mul(matrix a, matrix b){
matrix c;
for(int k=0; k<3; k++)for(int i=0; i<3; i++)for(int j=0; j<3; j++)c.a[i][j]=(a.a[i][k]*b.a[k][j]+c.a[i][j])%mod;
return c;
}
matrix fpow(matrix a, int b){
matrix c=a;
b--;
while(b){
if(b&1)c=mul(c,a);
a=mul(a,a);
b>>=1;
}
return c;
}
map <int,int> dp;
int dfs(int x){
if(x<=1)return x?(f.a[0][0]+f.a[1][1]+f.a[2][2])%mod:1;
if(dp.count(x))return dp[x];
if(x&1)return dp[x]=(f.a[0][0]+f.a[1][1]+f.a[2][2])%mod*dfs(x/2)%mod;
return dp[x]=(dfs(x/2)+dfs(x/2-1))%mod;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
g.a[0][0]=g.a[1][1]=g.a[2][2]=1;
f=fpow(g,n);
cout<<dfs(m)<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
3 2
output:
4
result:
ok "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
3 0
output:
1
result:
ok "1"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3656kb
input:
100 100
output:
319
result:
wrong answer 1st words differ - expected: '343406454', found: '319'