QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#764272#9479. And DNAmhb2010WA 0ms3656kbC++14879b2024-11-20 08:24:352024-11-20 08:24:35

Judging History

你现在查看的是最新测评结果

  • [2024-11-20 08:24:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3656kb
  • [2024-11-20 08:24:35]
  • 提交

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'