ログインしてください。
提出 #14498999
ソースコード 拡げる
#include <bits/stdc++.h>
#define endl '\n'
#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = 342;
const int mod = 998244353;
string s;
int n;
int k;
void read() {
cin >> s >> k;
n = SZ(s);
chkmin(k, n);
}
int dp[MAXN][MAXN][MAXN];
void add(int &x, int a) {
x += a;
if(x >= mod) x -= mod;
}
void solve() {
vector<int> pos0;
pos0.pb(-1);
for(int i = 0; i < n; i++) {
if(s[i] == '0') pos0.pb(i);
}
pos0.pb(n);
dp[0][0][0] = 1;
int m = SZ(pos0) - 1, z = n + 1 - m;
for(int i = 1; i <= m; i++) {
int actual_cnt_1 = pos0[i] - pos0[i - 1] - 1;
for(int q = 0; q <= k; q++) {
for(int bal = 0; bal <= z; bal++) {
if(dp[i - 1][bal][q]) {
for(int c = 0; c <= z; c++) {
int delta = c - actual_cnt_1;
int new_q = q + max(delta, 0);
if(new_q <= k && delta + bal >= 0) {
add(dp[i][delta + bal][new_q],
dp[i - 1][bal][q]);
}
}
}
}
}
}
int ans = 0;
for(int i = 0; i <= k; i++) {
add(ans, dp[m][0][i]);
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
read();
solve();
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Shift |
| ユーザ | radoslav11 |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 800 |
| コード長 | 1498 Byte |
| 結果 | AC |
| 実行時間 | 551 ms |
| メモリ | 64004 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 800 / 800 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| 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, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, s1.txt, s2.txt, s3.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 01.txt | AC | 136 ms | 23112 KiB |
| 02.txt | AC | 126 ms | 20692 KiB |
| 03.txt | AC | 294 ms | 33572 KiB |
| 04.txt | AC | 32 ms | 6892 KiB |
| 05.txt | AC | 104 ms | 19068 KiB |
| 06.txt | AC | 21 ms | 7616 KiB |
| 07.txt | AC | 157 ms | 25968 KiB |
| 08.txt | AC | 181 ms | 27564 KiB |
| 09.txt | AC | 4 ms | 4792 KiB |
| 10.txt | AC | 2 ms | 3624 KiB |
| 11.txt | AC | 551 ms | 63152 KiB |
| 12.txt | AC | 188 ms | 27196 KiB |
| 13.txt | AC | 546 ms | 64004 KiB |
| 14.txt | AC | 55 ms | 12400 KiB |
| 15.txt | AC | 176 ms | 19540 KiB |
| 16.txt | AC | 54 ms | 13168 KiB |
| 17.txt | AC | 5 ms | 5164 KiB |
| 18.txt | AC | 184 ms | 27208 KiB |
| 19.txt | AC | 44 ms | 5252 KiB |
| 20.txt | AC | 17 ms | 4652 KiB |
| 21.txt | AC | 40 ms | 5484 KiB |
| 22.txt | AC | 21 ms | 4860 KiB |
| 23.txt | AC | 17 ms | 10012 KiB |
| 24.txt | AC | 14 ms | 7984 KiB |
| 25.txt | AC | 17 ms | 4508 KiB |
| 26.txt | AC | 10 ms | 3948 KiB |
| 27.txt | AC | 36 ms | 14508 KiB |
| 28.txt | AC | 42 ms | 26844 KiB |
| 29.txt | AC | 5 ms | 3504 KiB |
| 30.txt | AC | 3 ms | 3616 KiB |
| 31.txt | AC | 2 ms | 3616 KiB |
| 32.txt | AC | 2 ms | 3660 KiB |
| 33.txt | AC | 3 ms | 3576 KiB |
| 34.txt | AC | 18 ms | 4468 KiB |
| 35.txt | AC | 46 ms | 5692 KiB |
| 36.txt | AC | 6 ms | 3624 KiB |
| s1.txt | AC | 2 ms | 3628 KiB |
| s2.txt | AC | 6 ms | 3648 KiB |
| s3.txt | AC | 5 ms | 4416 KiB |