QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#391973 | #7880. Streak Manipulation | Fiatiustitia | WA | 0ms | 3624kb | C++20 | 1.4kb | 2024-04-16 23:17:44 | 2024-04-16 23:17:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int f[N][6][2];
void solve()
{
int n, m, k;
cin >> n >> m >> k;
vector<int> cnts0(n + 1);
string s;
cin >> s;
s = '!' + s;
for (int i = 1; i <= n; i++)
cnts0[i] = cnts0[i - 1] + (s[i] == '0');
auto check = [&](int x)
{
for (int i = 0; i <= n; i++)
for (int j = 1; j <= k; j++)
f[i][j][0] = f[i][j][1] = INT32_MAX / 2;
f[0][0][0] = 0;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= k; j++)
{
if (i - x >= 0 && s[i - x] == '0')
f[i][j][1] = min(f[i][j][1], f[i - x][j - 1][0] + cnts0[i] - cnts0[i - x]);
if (s[i] == '0')
f[i][j][0] = min(f[i - 1][j][0], f[i - 1][j][1]);
}
}
return min(f[n][k][0], f[n][k][1]) <= m;
};
int l = 1, r = n, res = -1;
while (l <= r)
{
int mid = (l + r) >> 1;
if (check(mid))
{
res = mid;
l = mid + 1;
}
else
r = mid - 1;
}
cout << res << '\n';
}
int main()
{
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3624kb
input:
8 3 2 10110110
output:
2
result:
wrong answer 1st numbers differ - expected: '3', found: '2'