QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#592001 | #6841. Occupy the Cities | 333zhan | TL | 11ms | 4864kb | C++20 | 2.1kb | 2024-09-26 19:55:24 | 2024-09-26 19:55:25 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve () {
int n;
cin >> n;
string s;
cin >> s;
vector <bool> ok (n);
for (int i = 0; i < n; i ++) {
if (s[i] == '1') {
bool ok1 = true, ok2 = true;
if (i && s[i - 1] == '1') {
ok1 = false;
}
if (i < n - 1 && s[i + 1] == '1') {
ok2 = false;
}
if (ok1 && ok2) {
ok[i] = true;
}
}
}
auto check = [&] (int x) {
vector <int> must (n);
for (int i = 0; i < n; i ++) {
if (s[i] == '1') {
continue;
}
int j = i - 1;
while (j + 1 < n && s[j + 1] == '0') {
j ++;
}
if (i - 1 >= 0) {
if (! ok[i - 1] || ! must[i - 1]) {
if (i + x - 1 >= j) {
continue;
}
}
if (j + 1 >= n) {
return i + x - 1 - must[i - 1] >= j;
}
if ((i + x - 1 - must[i - 1]) + x < j) {
return false;
}
if (ok[j + 1] && i + x - 1 - must[i - 1] + x - 1 < j) {
must[j + 1] = 1;
}
} else {
if (j - i + 1 > x) {
return false;
}
if (ok[j + 1] && x - 1 < j - i + 1) {
must[j + 1] = 1;
}
}
i = j;
}
return true;
};
int l = 0, r = n;
while (l < r) {
int mid = (l + r) / 2;
if (check (mid)) {
r = mid;
} else {
l = mid + 1;
}
}
cout << l << '\n';
}
signed main () {
ios::sync_with_stdio (false);
cin.tie (nullptr);
int T = 1;
cin >> T;
while (T --) {
solve ();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3872kb
input:
5 3 010 4 0100 7 0001000 5 11111 6 010101
output:
2 2 4 0 1
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
2036 1 1 2 01 2 10 2 11 3 001 3 010 3 011 3 100 3 101 3 110 3 111 4 0001 4 0010 4 0011 4 0100 4 0101 4 0110 4 0111 4 1000 4 1001 4 1010 4 1011 4 1100 4 1101 4 1110 4 1111 5 00001 5 00010 5 00011 5 00100 5 00101 5 00110 5 00111 5 01000 5 01001 5 01010 5 01011 5 01100 5 01101 5 01110 5 01111 5 10000 5...
output:
0 1 1 0 2 2 1 2 1 1 0 3 2 2 2 1 1 1 3 1 1 1 2 1 1 0 4 3 3 3 2 2 2 3 2 2 1 2 1 1 1 4 2 2 1 2 1 1 1 3 1 1 1 2 1 1 0 5 4 4 3 3 3 3 3 2 2 2 2 2 2 2 4 2 2 2 2 1 1 1 3 1 1 1 2 1 1 1 5 2 2 2 2 1 1 1 3 1 1 1 2 1 1 1 4 2 2 1 2 1 1 1 3 1 1 1 2 1 1 0 6 5 5 4 4 4 4 4 3 3 3 3 3 3 3 4 2 2 2 2 2 2 2 3 2 2 2 2 2 2 ...
result:
ok 2036 lines
Test #3:
score: 0
Accepted
time: 4ms
memory: 3640kb
input:
1000 100 1011100101100000101100001011101111011001011101100011010110100101110011010111011101100111100010010101 100 0001001110011011010011111011001110001011010001111110111001100000001111000110101001000101000011000110 100 011011010100100100011000110111011111100100101100010000011101011110001000010011011...
output:
3 4 3 4 4 3 4 5 4 3 3 3 3 2 5 3 3 3 3 3 2 4 3 3 3 3 4 3 2 3 6 5 3 3 3 5 2 3 2 3 2 3 5 4 3 3 3 5 3 3 3 2 3 5 3 2 2 3 4 3 3 4 4 3 5 3 5 4 4 2 5 3 3 4 3 3 3 3 3 3 4 3 4 3 3 6 4 4 9 3 3 2 5 2 4 4 2 4 3 3 4 3 2 5 3 5 3 4 3 2 3 2 3 3 4 3 3 4 3 2 3 3 4 3 3 4 4 3 3 4 3 4 3 3 4 5 3 3 3 4 6 4 3 4 3 3 3 4 4 4 ...
result:
ok 1000 lines
Test #4:
score: 0
Accepted
time: 4ms
memory: 3660kb
input:
100 1000 101001000101110101101100110011101110001111000111000101100011110111111000000110110110000101100110010000010100011110011101111000110101010001101010101101111101111101010001101100011110000000000010011000000010010101001001100001010011011101110111100010000110001110011010000110000001101011000100010...
output:
6 5 4 5 4 5 4 5 5 5 4 5 6 5 4 4 5 5 4 5 5 6 5 5 4 5 5 7 4 7 5 5 8 6 4 4 5 3 5 5 4 4 5 7 6 5 7 6 4 7 5 5 5 4 4 5 4 4 5 4 6 4 5 4 5 4 6 6 6 4 10 5 5 5 4 4 6 5 5 7 6 4 5 5 6 6 6 7 4 4 4 5 6 5 6 4 5 6 5 3
result:
ok 100 lines
Test #5:
score: 0
Accepted
time: 11ms
memory: 4564kb
input:
1 100000 000101101111111110101100100000101111001010100001111011111000110000110111101101010110010111000000101010001011110001100110110001010000010010000010100100000000001101110110101101001010110111001010100110100111111101000110100111011111101011101100110001011000000000011111011100111110100100100010101...
output:
8
result:
ok single line: '8'
Test #6:
score: 0
Accepted
time: 11ms
memory: 4864kb
input:
1 100000 011010011100000110100111110110111110011001001000000111111100011100110010001110000111111010100110000111000100000001010010100110111001010010100111000000000111110101011101000001010100111100001110010101111100011000001011000111010111110010001111000011101100011110111100010101100010111101010001110...
output:
8
result:
ok single line: '8'
Test #7:
score: 0
Accepted
time: 4ms
memory: 3580kb
input:
1000 100 0000000000100010000000001100000000000010010101000010000000000000000000000010010000000000110000000010 100 0000000000000000000000000000000100000000000000000000001100000110000000000000010000010000100101000000 100 000010000000000000000000000000000000000000000000000000000010000000000000000000000...
output:
12 31 27 16 14 27 14 42 13 10 23 16 12 11 28 24 20 15 17 10 23 23 7 22 15 21 12 22 16 12 10 8 19 19 27 13 15 10 10 17 20 23 10 6 28 12 36 12 22 20 14 12 14 11 32 12 9 14 20 12 11 27 12 8 13 11 11 13 13 18 7 12 16 15 21 13 13 27 19 8 20 13 12 15 32 29 17 11 27 17 19 12 23 10 10 23 13 9 9 20 10 15 30 ...
result:
ok 1000 lines
Test #8:
score: 0
Accepted
time: 4ms
memory: 3584kb
input:
1000 100 1000000010000100000000000000000001100000011000000100100000000000110000000100100000000000001000000100 100 0000000000000010011000000010000010000000000000000000000000000000100100000100000000000010000000000000 100 000000010010000000000000001000000000000000000000010000001001000001000001000000010...
output:
10 16 20 17 15 15 19 16 12 21 32 11 43 23 17 14 16 20 9 8 14 40 13 9 13 13 41 13 10 13 18 29 15 22 11 7 17 10 31 13 11 27 15 13 32 19 14 12 19 10 27 16 14 22 23 12 18 14 18 12 13 18 48 18 9 11 13 19 11 40 19 17 10 11 15 11 10 24 9 19 10 22 18 24 14 20 11 10 21 16 11 21 16 13 16 45 26 12 14 10 11 14 ...
result:
ok 1000 lines
Test #9:
score: 0
Accepted
time: 4ms
memory: 3588kb
input:
1000 100 0000000000100000001000000000000000010000000000010000000010100000000000000000000000101000000000000001 100 0000000000010000000000000001001000100000001000000000000010100001000000000000000000100000000000000000 100 000100000000000000000000010000100000000000000100000000000000000010000000100000000...
output:
12 17 11 8 15 16 22 26 22 13 17 14 15 21 10 7 10 51 14 13 22 10 40 21 34 16 16 18 12 17 14 34 22 21 11 16 15 15 14 9 11 14 8 20 25 11 19 20 14 18 42 9 14 30 9 33 18 9 12 9 20 19 17 18 17 19 13 14 32 16 14 27 18 14 17 12 9 58 34 8 30 14 16 19 16 21 13 23 28 15 33 10 11 41 19 27 24 15 11 17 18 21 14 1...
result:
ok 1000 lines
Test #10:
score: -100
Time Limit Exceeded
input:
1 1000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
435