QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#587235#9174. Game DesignyhdddWA 0ms3964kbC++201.2kb2024-09-24 18:37:472024-09-24 18:37:48

Judging History

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

  • [2024-09-24 18:37:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3964kb
  • [2024-09-24 18:37:47]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=5010;
const int inf=1e18;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int n;
char s[maxn];
int dp[2][maxn],cur;
void work(){
	scanf("%s",s+1);n=strlen(s+1);
	mems(dp,0);dp[0][0]=1;
	for(int i=1;i<=n+1;i++){
		mems(dp[i&1],0);
		for(int j=0;j<=n;j++)if(dp[cur][j]){
			(dp[i&1][j+1]+=dp[cur][j])%=mod;
			(dp[i&1][j]+=dp[cur][j]*j)%=mod;
			if(s[i]=='1')(dp[i&1][j]+=dp[cur][j]*j)%=mod;
			if(s[i]=='1'&&j)(dp[i&1][j-1]+=dp[cur][j]*j*j)%=mod;
			// cout<<i-1<<" "<<j<<" "<<dp[cur][j]<<"\n";
		}
		cur^=1;
	}
	printf("%lld\n",dp[n&1][0]);
}

// \
444

bool Med;
int T;
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=read();
	while(T--)work();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3964kb

input:

4
0101
1010010010001010
11111
10100100011000010010101001001001

output:

3
0
44
393298077

result:

ok 4 number(s): "3 0 44 393298077"

Test #2:

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

input:

4
01
11
10
00

output:

1
0
0
0

result:

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