QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#273265 | #7880. Streak Manipulation | ucup-team484# | WA | 99ms | 10488kb | C++17 | 1.4kb | 2023-12-02 22:33:52 | 2023-12-02 22:33:52 |
Judging History
answer
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define st first
#define nd second
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n, m, k; cin >> n >> m >> k;
string s; cin >> s;
vector<int> pref(n + 1);
for (int i = 0; i < n; i++) {
pref[i] = (s[i] == '0');
if (i > 0)
pref[i] += pref[i - 1];
}
pref[n] = pref[n - 1];
auto ok = [&](int C) {
vector<vector<int>> dp(k + 1, vector<int>(n + 1, mod));
vector<int> nx(n + 1), sm(n + 1);
for (int i = 0; i < n; i++) {
nx[i] = min(n, max(i + C, i > 0 ? nx[i - 1] : 0));
while (nx[i] < n && s[nx[i]] == '1')
nx[i]++;
sm[i] = pref[nx[i] - 1];
if (i > 0)
sm[i] -= pref[i - 1];
if (i == 0 || s[i - 1] == '0')
dp[1][nx[i]] = min(dp[1][nx[i]], sm[i]);
}
for (int i = 1; i < k; i++)
for (int j = 1; j < n; j++) {
if (nx[j] - j >= C && s[j - 1] == '0')
dp[i + 1][nx[j]] = min(dp[i + 1][nx[j]], dp[i][j - 1] + sm[j]);
dp[i][j] = min(dp[i][j], dp[i][j - 1]);
}
for (int i = 0; i <= n; i++)
if (dp[k][i] <= m)
return 1;
return 0;
};
int lo = 1, hi = n;
while (lo <= hi) {
int mi = (lo + hi) / 2;
if (ok(mi))
lo = mi + 1;
else
hi = mi - 1;
}
if (hi == 0)
hi = -1;
cout << hi << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
8 3 2 10110110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
12 3 3 100100010011
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
4 4 4 0000
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
1000 200 5 0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...
output:
99
result:
ok 1 number(s): "99"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3884kb
input:
1000 200 5 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
40
result:
ok 1 number(s): "40"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3884kb
input:
1000 200 5 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
-1
result:
ok 1 number(s): "-1"
Test #7:
score: 0
Accepted
time: 30ms
memory: 8908kb
input:
200000 5 3 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 36ms
memory: 8188kb
input:
200000 5 2 0001010000000000000000010011000001000000000000000001100000000001000000000000010011000010000000000110000010000010000100000000001001010000011000100000000001001000000000011110000100000011000000100110100110001011000000000000000000000000110001000000100000011100010011010001010010010100000000000...
output:
13
result:
ok 1 number(s): "13"
Test #9:
score: 0
Accepted
time: 99ms
memory: 10488kb
input:
200000 5 5 0001100001100000001011100010111101100100110001000011001011111101110100000000000111101001110100010101010100110100100011001100000010110111110010111011110100100101011001100101001010110100011101011001000101011110110010001011111101011101011010101101010001111110101001001110000000000010101001001...
output:
17
result:
ok 1 number(s): "17"
Test #10:
score: 0
Accepted
time: 79ms
memory: 10408kb
input:
200000 5 5 1011101011100110010111011011101110111111101111110111101111011110110111111101111011110101101110001100111110010101111011111101111111111111110110111111111011111111111111111111111111011100101111001110011100111100001111111111110101111011110010111001101111111111110110010101100111111111111111011...
output:
45
result:
ok 1 number(s): "45"
Test #11:
score: 0
Accepted
time: 40ms
memory: 9852kb
input:
200000 5 4 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
24879
result:
ok 1 number(s): "24879"
Test #12:
score: 0
Accepted
time: 64ms
memory: 10408kb
input:
200000 5 5 1010101010010101001010100101011010110010100101000010100101010101001010110101010101010101101010110101010101010101011001010101010101010101011001010101010100010101010010101000101001010101010110010101010110101101010111101010110101010101010010101010110111010010110111011010101010101110111001101...
output:
9
result:
ok 1 number(s): "9"
Test #13:
score: -100
Wrong Answer
time: 17ms
memory: 7208kb
input:
200000 5 1 1001001011010101010101010101110101010100101001001010101101110101011010110101010110101010101011010101010101010010101010101000100110111110101101010101101011010101010101011010101010101010101010010101010101010110101001010101010101010110101010101010101011011010001010101011010101010101010101001...
output:
200000
result:
wrong answer 1st numbers differ - expected: '20', found: '200000'