QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#272179 | #7880. Streak Manipulation | ucup-team191# | WA | 1ms | 5692kb | C++14 | 1.0kb | 2023-12-02 16:21:09 | 2023-12-02 16:21:10 |
Judging History
answer
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 2e5 + 500;
const int INF = 0x3f3f3f3f;
int cst[N], P[N], A[N], dp[N][6], n, m, k;
int get(int l, int r) {
return P[r] - (l ? P[l - 1] : 0);
}
bool check(int x) {
for(int i = 0;i + x <= n;i++) {
cst[i] = (int)(i && A[i - 1]) + x - get(i, i + x - 1);
}
for(int j = 1;j <= k;j++) {
for(int i = 0;i <= n;i++) dp[i][j] = INF;
if(j == k) {
for(int i = 0;i + x <= n;i++)
dp[i + x][j] = min(dp[i + x][j], dp[i][j - 1] + cst[i]);
} else {
for(int i = 0;i + x + 1 <= n;i++)
dp[i + x + 1][j] = min(dp[i + x + 1][j], dp[i][j - 1] + cst[i]);
}
}
for(int i = 0;i <= n;i++)
if(dp[i][k] <= m) return 1;
return 0;
}
int main(){
scanf("%d%d%d", &n, &m, &k);
for(int i = 0;i < n;i++) {
char c; scanf(" %c", &c);
A[i] = c - '0'; P[i] = (i ? P[i - 1] : 0) + A[i];
}
int ans = 0;
for(int i = 17;i >= 0;i--)
if(ans + (1 << i) <= n / k && check(ans + (1 << i))) ans += (1 << i);
printf("%d\n", ans ? ans : -1);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3664kb
input:
8 3 2 10110110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
12 3 3 100100010011
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5692kb
input:
4 4 4 0000
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3720kb
input:
1000 200 5 0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...
output:
90
result:
wrong answer 1st numbers differ - expected: '99', found: '90'