QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#537259 | #7880. Streak Manipulation | s1amese | WA | 3ms | 13864kb | C++20 | 1.4kb | 2024-08-30 02:52:10 | 2024-08-30 02:52:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, m, k, S[N], a[N], dp[N][6], mn[N][6], lp[N];
void ckmn(int &x, int y) {
if (x > y)
x = y;
}
bool check(int len) {
memset(dp, 0x3f, sizeof dp);
memset(mn, 0x3f, sizeof mn);
for (int i = 1; i <= n; i++)
if (i >= len) {
dp[i][1] = S[i] - S[i - len];
mn[i][1] = min(mn[i - 1][1], dp[i][1]);
}
for (int i = 1; i <= n; i++)
for (int j = 2; j <= k; j++) {
if (i >= len + 1) {
int p = lp[i - len];
if (p > 0)
ckmn(dp[i][j], mn[p - 1][j - 1] + S[i] - S[p]);
}
mn[i][j] = mn[i - 1][j]; //????
ckmn(mn[i][j], dp[i][j]); // ????
}
return mn[n][k] <= m;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> k;
string s;
cin >> s;
int pos = 0;
for (int i = 1; i <= n; i++) {
int x = s[i - 1] - '0';
a[i] = x;
S[i] = S[i - 1] + (a[i] == 0);
if (!a[i])
pos = i;
lp[i] = pos;
}
int l = 0, r = n;
while (l + 1 < r) {
int mid = l + r >> 1;
if (check(mid))
l = mid;
else
r = mid;
}
if (check(l))
cout << l;
else
cout << -1;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 13216kb
input:
8 3 2 10110110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 13836kb
input:
12 3 3 100100010011
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 13864kb
input:
4 4 4 0000
output:
0
result:
wrong answer 1st numbers differ - expected: '-1', found: '0'