QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#391974 | #7880. Streak Manipulation | Fiatiustitia | WA | 0ms | 3504kb | C++20 | 1.4kb | 2024-04-16 23:25:47 | 2024-04-16 23:25:47 |
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 = 0; 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)
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]);
else
f[i][j][0] = f[i - 1][j][0];
}
}
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;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3504kb
input:
8 3 2 10110110
output:
1
result:
wrong answer 1st numbers differ - expected: '3', found: '1'