QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#668013#9489. 0100 InsertionfryanWA 1ms4168kbC++171.4kb2024-10-23 10:38:052024-10-23 10:38:14

Judging History

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

  • [2024-10-23 10:38:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4168kb
  • [2024-10-23 10:38:05]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
#define i64 int64_t
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()

const int mod = 998244353;
const int mxn = 51;

int n,s[mxn];
i64 dp[mxn][4*mxn][mxn][2];

/*
0 : 1
1 : -3
dp[i][j][k] = prefix sum is n+i, prefix min is -j, last character is k
*/

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	cin>>n;
	for (int i=0; i<n; i++) {
		char c; cin>>c;
		if (c=='?') s[i]=2;
		else s[i]=c-'0';
	}
	reverse(s,s+n);
//	cout<<"\n\n";
	dp[0][n][0][0] = 1;
	for (int i=0; i<=n; i++) {
		for (int j=0; j<4*n; j++) {
			for (int k=0; k<mxn; k++) {
				if (dp[i][j][k][0] || dp[i][j][k][1]) {
		//			cout<<i<<" "<<j<<" "<<k<<" 0: "<<dp[i][j][k][0]<<"\n";
		//			cout<<i<<" "<<j<<" "<<k<<" 1: "<<dp[i][j][k][1]<<"\n\n";
				} else {
					continue;
				}
				if (s[i]==0 || s[i]==2) {
					dp[i+1][j+1][k][0] += dp[i][j][k][0];
					dp[i+1][j+1][k][0] += dp[i][j][k][1];
					dp[i+1][j+1][k][0] %= mod;
				}
				if (s[i]==1 || s[i]==2) {
				//	cout<<i<<"~\n";
					if (i==n-1 || i==1 || i==0) continue;
					int pfx = j-3-n;
					int pmn = -k;
					if (pfx+1 < pmn) continue;
					dp[i+1][j-3][max(n-j+3,k)][1] += dp[i][j][k][0];
					dp[i+1][j-3][max(n-j+3,k)][1] %= mod;
				}
			}
		}
	}
	
	int res=0;
	
	for (int i=0; i<n; i++) {
		res += dp[n][n][i][0];
		res %= mod;
	}
	cout<<res;
		
	return 0;
}

详细

Test #1:

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

input:

8
0??0?100

output:

2

result:

ok "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3664kb

input:

4
?10?

output:

1

result:

ok "1"

Test #3:

score: 0
Accepted
time: 1ms
memory: 4168kb

input:

28
???????????0???0??????1???0?

output:

2023

result:

ok "2023"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

4
????

output:

1

result:

ok "1"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

8
11111111

output:

0

result:

ok "0"

Test #6:

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

input:

500
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...

output:

0

result:

wrong answer 1st words differ - expected: '870731023', found: '0'