Submission #34682408
Source Code Expand
#include <atcoder/modint>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using mint = atcoder::modint998244353;
int main() {
string s;
cin >> s;
int n = s.length();
// 各ボールの個数の累積和
vector<int> rsum(n * 2 + 1), bsum(n * 2 + 1);
rsum[0] = bsum[0] = 0;
for (int i = 0; i < n; ++i) {
int b = s[i] - '0';
rsum[i + 1] = rsum[i] + 2 - b;
bsum[i + 1] = bsum[i] + b;
}
for (int i = n; i < n * 2; ++i) {
rsum[i + 1] = rsum[i];
bsum[i + 1] = bsum[i];
}
auto dp = vector(rsum[n] + 1, vector(bsum[n] + 1, mint(0)));
dp[0][0] = 1;
for (int r = 0; r <= rsum[n]; ++r) {
for (int b = 0; b <= bsum[n]; ++b) {
if (r + b == n * 2) continue;
// 赤ボールを置けるか?
if (rsum[r + b + 1] > r) dp[r + 1][b] += dp[r][b];
// 青ボールを置けるか?
if (bsum[r + b + 1] > b) dp[r][b + 1] += dp[r][b];
}
}
cout << dp[rsum[n]][bsum[n]].val() << "\n";
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - Pass |
| User | Tiramister |
| Language | C++ (GCC 9.2.1) |
| Score | 900 |
| Code Size | 1042 Byte |
| Status | AC |
| Exec Time | 48 ms |
| Memory | 19104 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 900 / 900 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | s1.txt, s2.txt, s3.txt |
| All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, s1.txt, s2.txt, s3.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | AC | 46 ms | 19104 KiB |
| 02.txt | AC | 43 ms | 18972 KiB |
| 03.txt | AC | 43 ms | 18972 KiB |
| 04.txt | AC | 44 ms | 18972 KiB |
| 05.txt | AC | 48 ms | 18872 KiB |
| 06.txt | AC | 44 ms | 18916 KiB |
| 07.txt | AC | 46 ms | 18932 KiB |
| 08.txt | AC | 43 ms | 19040 KiB |
| 09.txt | AC | 43 ms | 18932 KiB |
| 10.txt | AC | 42 ms | 18972 KiB |
| 11.txt | AC | 3 ms | 3784 KiB |
| 12.txt | AC | 44 ms | 19040 KiB |
| 13.txt | AC | 2 ms | 3624 KiB |
| 14.txt | AC | 34 ms | 15336 KiB |
| 15.txt | AC | 32 ms | 15220 KiB |
| 16.txt | AC | 32 ms | 15352 KiB |
| 17.txt | AC | 32 ms | 14708 KiB |
| 18.txt | AC | 32 ms | 15140 KiB |
| 19.txt | AC | 37 ms | 15052 KiB |
| 20.txt | AC | 39 ms | 17716 KiB |
| 21.txt | AC | 21 ms | 11876 KiB |
| 22.txt | AC | 36 ms | 16068 KiB |
| 23.txt | AC | 33 ms | 15804 KiB |
| 24.txt | AC | 34 ms | 16276 KiB |
| 25.txt | AC | 36 ms | 16640 KiB |
| 26.txt | AC | 3 ms | 3600 KiB |
| 27.txt | AC | 3 ms | 3552 KiB |
| 28.txt | AC | 2 ms | 3600 KiB |
| s1.txt | AC | 2 ms | 3628 KiB |
| s2.txt | AC | 2 ms | 3620 KiB |
| s3.txt | AC | 2 ms | 3484 KiB |