QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#72260#4812. Counting SequenceJinTianHaoWA 2ms7472kbC++171.7kb2023-01-15 11:39:492023-01-15 11:39:53

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-15 11:39:53]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7472kb
  • [2023-01-15 11:39:49]
  • 提交

answer

#include <bits/stdc++.h>
#define inf 1000000007
#define mod 998244353
// #define int long long
// #pragma GCC optimize("Ofast","inline","-ffast-math")
// #pragma GCC target("avx,sse2,sse3,sse4,mmx")
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n,c,siz,ans;
int dp1[2][600005];
int dp2[300005][900];
signed main()
{
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	read(n);read(c);if(!c) ans=1;
	siz=sqrt(2*n)-10;siz=max(siz,0);
	while((siz+2)*(siz+1)<=2*n) ++siz;
	dp1[1][n]=1;
	for(int i=1;i<siz;++i)
	{
		for(int j=0;j<=2*n;++j)
			dp1[i&1^1][j]=0;
		for(int j=0;j<=2*n;++j)
		{
			//add <
			(dp1[i&1^1][j+i]+=dp1[i&1][j])%=mod;
			//add >
			(dp1[i&1^1][j-i]+=1ll*c*dp1[i&1][j]%mod)%=mod;
		}
		for(int a=siz+1;a<=n;++a)
		{
			int sum=2*n-a*i;
			if(sum>=0&&sum<=2*n) (ans+=dp1[i&1][sum])%=mod;
		}
	}
	for(int i=1;i<=n;++i)
	{
		if(i<=siz) (dp2[i][i]+=1)%=mod;
		for(int j=1;j<900;++j)
		{
			if(!dp2[i][j]) continue;
			if(i+j-1<=n&&j>1) (dp2[i+j-1][j-1]+=1ll*c*dp2[i][j]%mod)%=mod;
			if(i+j+1<=n&&j<899) (dp2[i+j+1][j+1]+=dp2[i][j])%=mod;
		}
	}
	for(int i=1;i<900;++i)
		(ans+=dp2[n][i])%=mod;
	for(int a=siz+1;a<=n;++a)
		for(int m=siz;m<=siz;++m)
		{
			int sum=2*n-a*m;
			if(sum>=0&&sum<=2*n) (ans+=dp1[m&1][sum])%=mod;
		}
	writeln(ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7472kb

input:

5 3

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 5408kb

input:

1 0

output:

2

result:

wrong answer 1st numbers differ - expected: '1', found: '2'