QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#405600 | #7880. Streak Manipulation | Godwang | WA | 1ms | 3768kb | C++14 | 2.3kb | 2024-05-06 10:03:48 | 2024-05-06 10:03:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int dp[200003][8][2];
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n, m, k;
string s;
cin >> n >> m >> k >> s;
vector<int> cnt_0(n + 1);
s.insert(0, " ");
for (int i = 1; i <= n; ++i)
cnt_0[i] = cnt_0[i - 1] + (s[i] == '0');
int l = 0, r = 2e5+1;
auto check = [&](int tar)
{
for (int i = 0; i <= n; ++i)
{
for (int j = 0; j <= k; ++j)
{
if(j==0)
{
dp[i][0][1]=0x3f3f3f3f;
}
else
{
dp[i][j][0] = dp[i][j][1] = 0x3f3f3f3f;
}
}
}
for (int i = 1; i <= n; ++i)
{
for (int j = 0; j <= k; ++j)
{
if (s[i] == '1')
{
dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][0]);
dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][1]);//实际上是一种泛化的讨论
}
else
{
dp[i][j][0] = min({dp[i][j][0], dp[i - 1][j][0], dp[i - 1][j][1]});
dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][1] + 1);
}
if (j >= 1 && i >= tar && dp[i - tar][j - 1][0] != 0x3f3f3f3f)
{
dp[i][j][1] = min(dp[i][j][1], dp[i - tar][j - 1][0] + cnt_0[i] - cnt_0[i - tar]);
}
}
}
// for (int i = 1; i <= n; ++i) {
// for (int j = 0; j <= k; ++j) {
// cerr << i << ' ' << j << ' ' << 0 << ' ' << dp[i][j][0] << '\n';
// cerr << i << ' ' << j << ' ' << 1 << ' ' << dp[i][j][1] << '\n';
// }
// }
return min(dp[n][k][0], dp[n][k][1]) <= m;
};
// check(3);
int ans=-1;
while (l < r)
{
int mid = (l + r ) >> 1;
// cerr << l << ' ' << r << ' ' << mid << '\n';
if (check(mid))
{
ans=mid;
l = mid+1;
}
else
{
r = mid;
}
}
cout<<ans;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3576kb
input:
8 3 2 10110110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
12 3 3 100100010011
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3768kb
input:
4 4 4 0000
output:
0
result:
wrong answer 1st numbers differ - expected: '-1', found: '0'