QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#349980 | #6726. Turn It Off | wudibaolong# | AC ✓ | 17ms | 4400kb | C++14 | 1.3kb | 2024-03-10 10:38:58 | 2024-03-10 10:38:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int T; cin >> T;
while (T--) {
int n, lmt; cin >> n >> lmt;
string state; cin >> state;
state = " " + state;
bool flag = 1;
for (int i = 1; i <= n; ++i) {
if (state[i] == '1') {
flag = 0;
}
}
if(flag) {
cout << "0\n";
continue;
}
auto check = [&](int L) {
// cout << L << '\n';
int cnt = 0;
string tmp = state;
for (int i = 1; i <= n; ++i) {
if (tmp[i] == '1') {
int Len = i + L - 1;
for (; i <= Len and i <= n; ++i) {
tmp[i] = '0';
}
i--;
cnt++;
}
}
// cout << L << " " << cnt << '\n';
return cnt <= lmt;
};
// cout << "helloworld\n";
int l = 1, r = n;
while (l < r) {
int mid = (l + r) >> 1;
// cout << mid << '\n';
if (check(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
cout << l << '\n';
}
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3592kb
input:
2 10 4 0101011111 3 1 010
output:
3 1
result:
ok 2 number(s): "3 1"
Test #2:
score: 0
Accepted
time: 17ms
memory: 4400kb
input:
1109 47 36 11101110101001111110101101100001000011101001011 6 5 100010 35 26 00011111000000101010011010100101111 71 45 11101001000111011101101000000000010001100100110000001000011011001011000 32 23 00000100011110010101000110010110 36 30 110110000000000011010001100011111100 21 8 010000011010011101100 9...
output:
1 1 1 1 1 1 2 4 10 2 2 3 3 1 2 1 1 1 1 2 2 2 6 7 1 1 1 1 1 1 1 3 1 1 2 3 1 1 3 1 1 6 1 1 5 1 1 3 10 19 1 1 1 4 1 1 2 1 2 1 1 2 1 1 60 17 3 3 2 2 1 1 4 1 1 1 1 1 2 2 1 3 5 2 1 1 4 2 1 1 3 1 1 1 1 1 5 2 3 1 2 1 1 1 1 2 1 1 2 1 1 81 1 4 1 1 1 2 1 44 1 5 2 3 1 1 1 2 1 8 1 1 3 1 1 2 1 46 1 1 1 1 1 1 1 1 ...
result:
ok 1109 numbers