QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#673841 | #9489. 0100 Insertion | professor_panda | TL | 1ms | 3620kb | C++14 | 2.0kb | 2024-10-25 10:56:38 | 2024-10-25 10:56:41 |
Judging History
answer
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long LL;
LL MOD = 998244353;
int main() {
int N;
cin >> N;
vector<char> S(N);
for (int i = 0; i < N; i++) cin >> S[N- 1 - i];
if (S[0] == '1' || S[1] == '1' || S[N - 1] == '1') {
cout << 0 << endl;
return 0;
}
// m[A][B][C]: A = (# of 0) - 3*(# of 1) + N / 4, B = min preA, C = 0 or 1
vector<vector<vector<int>>> m(N+1, vector<vector<int>>(N/2+1, vector<int>(2, 0)));
m[2+N/4][N/4][0] = 1;
for (int pos = 2; pos <N;pos++) {
vector<vector<vector<int>>> mp(N+1, vector<vector<int>>(N/2+1, vector<int>(2, 0)));
if (S[pos] == '?' || S[pos] == '0') {
// 0
for (int a = 1; a <= N; a++) {
for (int b = 0; b <= min(a, N/2); b++) {
mp[a][b][0] = (m[a - 1][b][0] + m[a - 1][b][1]) % MOD;
}
}
}
if (S[pos] == '?' || S[pos] == '1') {
// 1
for (int a = 0; a <= N-3; a++) {
for (int b = 0; b <= min(a, N/2); b++) {
mp[a][b][1] = m[a+3][b][0];
if (a == b && b < N/2) {
mp[a][b][1] += m[a+3][b+1][0];
mp[a][b][1] %= MOD;
}
}
}
}
swap(m, mp);
// for (int a = 0; a <= 100;a++) cout << "#";
// cout << endl;
// for (int a = 0; a <= N; a++) {
// for (int b = 0; b <= N/2; b++) {
// if (m[a][b][0] > 0) cout << "#0-#1*3:" << a - N / 4 << " prevmin:" << b - N / 4 << " 0:" << m[a][b][0] << endl;
// if (m[a][b][1] > 0) cout << "#0-#1*3:" << a - N / 4 << " prevmin:" << b - N / 4 << " 1:" << m[a][b][1] << endl;
// }
// }
}
LL ans = 0;
for (int b = 0; b <= N/4; b++) {
ans += m[N/4][b][0];
ans %= MOD;
}
cout << ans << endl;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3460kb
input:
8 0??0?100
output:
2
result:
ok "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
4 ?10?
output:
1
result:
ok "1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
28 ???????????0???0??????1???0?
output:
2023
result:
ok "2023"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
4 ????
output:
1
result:
ok "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
8 11111111
output:
0
result:
ok "0"
Test #6:
score: -100
Time Limit Exceeded
input:
500 ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
870731023