QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#622835 | #7880. Streak Manipulation | wpoem | WA | 1ms | 3676kb | C++20 | 1.3kb | 2024-10-09 06:40:49 | 2024-10-09 06:40:49 |
Judging History
answer
#include<bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define debug(...) 42
#endif
using i64 = long long;
namespace ranges = std::ranges;
constexpr int OP = 1E9;
void solve()
{
int n, m, k; std::cin >> n >> m >> k;
std::string s; std::cin >> s; s = " " + s; std::vector<int> pre(n + 1); for (int i = 1; i <= n; i++) {pre[i] = pre[i - 1] + (s[i] == '0');}
auto chmin = [&](auto& a, auto b) {a = std::min(a, b);};
auto check = [&](int& len) {
std::vector dp(n + 1, std::array<std::array<int, 2>, 6>()); for (auto& dpi : dp) for (auto& dpij : dpi) {ranges::fill(dpij, OP);}
dp[0][0][0] = 0;
for (int i = 1; i <= n; i++) for (int j = 0; j <= k; j++) {
if (i >= len and j >= 1) {chmin(dp[i][j][1], dp[i - len][j - 1][0] + pre[i] - pre[i - len]);}
chmin(dp[i][j][0], std::min(dp[i - 1][j][1], dp[i - 1][j][0]));
}
return ranges::min(dp[n][k]) <= m;
};
int lo{}, hi{n}; while (lo <= hi) {int mid{lo + hi >> 1}; check(mid) ? lo = mid + 1 : hi = mid - 1;}
std::cout << lo - 1 << "\n";
}
signed main()
{
std::cin.tie(nullptr)->sync_with_stdio(false);
int _(1);
#ifdef tests
std::cin >> _;
#endif
while(_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3580kb
input:
8 3 2 10110110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
12 3 3 100100010011
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3676kb
input:
4 4 4 0000
output:
0
result:
wrong answer 1st numbers differ - expected: '-1', found: '0'