QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#149385 | #6841. Occupy the Cities | qzez# | AC ✓ | 15ms | 14272kb | C++14 | 1.3kb | 2023-08-24 15:17:43 | 2023-08-24 15:17:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
cerr<<x<<' ',debug(y...);
}
const int N=1e6+10,INF=1e9;
int T,n;
char a[N];
int f[N][2];
void get(){
scanf("%d%s",&n,a+1);
vector<int>p;
for(int i=1;i<=n;i++)if(a[i]=='1')p.push_back(i);
int len=p.size();
for(int i=0;i<len;i++){
for(int j=0;j<2;j++)f[i][j]=INF;
}
f[0][0]=p[0]-1,f[0][1]=p[0]>1?p[0]:0;
for(int i=1;i<len;i++){
int cnt=p[i]-p[i-1]-1;
if(!cnt){
f[i][0]=f[i][1]=min(f[i-1][0],f[i-1][1]);
}else{
f[i][0]=min(max(f[i-1][0],cnt/2+1),max(f[i-1][1],(cnt+1)/2));
f[i][1]=min(max(f[i-1][0],(cnt+1)/2+1),max(f[i-1][1],cnt/2+1));
}
}
// debug(f[len-1][0],f[len-1][1]);
int res1=p.back()<n?max(f[len-1][0],n-p.back()+1):f[len-1][0];
int res2=max(f[len-1][1],n-p.back());
printf("%d\n",min(res1,res2));
}
int main(){
for(scanf("%d",&T);T--;)get();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3768kb
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: 2ms
memory: 3892kb
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: 3ms
memory: 5848kb
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: 2ms
memory: 4092kb
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: 2ms
memory: 8344kb
input:
1 100000 000101101111111110101100100000101111001010100001111011111000110000110111101101010110010111000000101010001011110001100110110001010000010010000010100100000000001101110110101101001010110111001010100110100111111101000110100111011111101011101100110001011000000000011111011100111110100100100010101...
output:
8
result:
ok single line: '8'
Test #6:
score: 0
Accepted
time: 3ms
memory: 8000kb
input:
1 100000 011010011100000110100111110110111110011001001000000111111100011100110010001110000111111010100110000111000100000001010010100110111001010010100111000000000111110101011101000001010100111100001110010101111100011000001011000111010111110010001111000011101100011110111100010101100010111101010001110...
output:
8
result:
ok single line: '8'
Test #7:
score: 0
Accepted
time: 0ms
memory: 5848kb
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: 2ms
memory: 6124kb
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: 2ms
memory: 3792kb
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: 0
Accepted
time: 6ms
memory: 6864kb
input:
1 1000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
435
result:
ok single line: '435'
Test #11:
score: 0
Accepted
time: 2ms
memory: 6188kb
input:
1 1000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
3424
result:
ok single line: '3424'
Test #12:
score: 0
Accepted
time: 6ms
memory: 8752kb
input:
1 1000000 10100100000000000000000001000000000001001000000010110000000000001000001010001100000101010010000010000001111000000110001101000000110100000010000000010000000000000000010001010000001000100100110001000100011100000011001000001000010100001000000000000010010100000001010000000000001000010000100101...
output:
28
result:
ok single line: '28'
Test #13:
score: 0
Accepted
time: 5ms
memory: 8700kb
input:
1 1000000 10001100000011000000100110010100101010100000001100000100000000001000110000000000000011000100000101000010011100000100100011100000110011110100000100001010000101001000001110000000100100111001000000001001011010001001111011000100001100000000000100001101000100000001000000001000010001100001000000...
output:
25008
result:
ok single line: '25008'
Test #14:
score: 0
Accepted
time: 0ms
memory: 9072kb
input:
1 1000000 10101101010100110100001011000000011100100010001010000000010010000100101010000001000000100011000000000000010000000001000111001101100001000011000001010110010000001000100100000000101001000010010000000010000000010110000100010000101001010000001010000000111000010011000100000000010110010100000010...
output:
50002
result:
ok single line: '50002'
Test #15:
score: 0
Accepted
time: 5ms
memory: 8808kb
input:
1 1000000 11000000011101000010000111101010011000001110000001010011000100111010010000000001000000000011111001001000111000100001000000000100110010010000001000000100100000010010000011000000100001000100001101000000110001000000110000011010110100011110001000010000101001000000100010010110110000000000000111...
output:
19
result:
ok single line: '19'
Test #16:
score: 0
Accepted
time: 5ms
memory: 9176kb
input:
1 1000000 10011000000001100001010001111011101001101110101010000001100001000100010010010001000011100101001100011110101110000000101001001000011101011000000100011100000000001001001000100000110000001000000000011000101000010010000101000110000011100100011100001011101110011001011100000100001000010000101000...
output:
50002
result:
ok single line: '50002'
Test #17:
score: 0
Accepted
time: 12ms
memory: 11252kb
input:
1 1000000 10011000000000001101000010001000000010101000001010110011000000010010001100001100010000110000000000000101000100100010011000001010001000011001010001001000001100000000000110000001010110000000100010010000000000000000100101100010000101001000010110000101010110100000001011000110000001000010000110...
output:
21
result:
ok single line: '21'
Test #18:
score: 0
Accepted
time: 9ms
memory: 11856kb
input:
1 1000000 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
150000
result:
ok single line: '150000'
Test #19:
score: 0
Accepted
time: 7ms
memory: 11708kb
input:
1 1000000 11010010111111011011011111000111011110010111101010011110101010111001100110111101001111101011101111010011110101001011110110111111110100010111010101100011011001111111111001100110110101011111001110110011011110011110110101011000010011011010111100111011101111011111110111110110111001111000110011...
output:
100000
result:
ok single line: '100000'
Test #20:
score: 0
Accepted
time: 13ms
memory: 11152kb
input:
1 1000000 11011001111110011111111100010101111111010100010010101111010000011110010101011001011010101001101100001001100011011000100100001101100100110100001000000100100111100110010111100010100110100011001101001111011010001000001010001111100001110011000010000110010100011000001110011101111010000111100001...
output:
50003
result:
ok single line: '50003'
Test #21:
score: 0
Accepted
time: 4ms
memory: 14272kb
input:
1 1000000 10100110111101111110101011000111101110011111011110101001010110101011011101011100011111011111111011010111001101111100001011111011100010110100011001110011100000011011101111011110110011001000010011111111110101001110110111111101010010100110110111001101010100101111011011010111110110011101111010...
output:
50002
result:
ok single line: '50002'
Test #22:
score: 0
Accepted
time: 5ms
memory: 11796kb
input:
1 1000000 11111111110100101111101000101101100010010111101101001001100011111001111010101100001000011010000010011101111100100110011101101011010110110001110111111011001111110010110010101111100110010000001010010110010111110101001001001111011101111110111011100011110101010111111110110110111101111111011111...
output:
40000
result:
ok single line: '40000'
Test #23:
score: 0
Accepted
time: 7ms
memory: 11692kb
input:
1 1000000 11110001001000011010011010100100011101100001111111111011111001011110110010010010010010111010101001001101100111000110001111011111101111101010111111110111101101111000110110011101111000001011100111100100000010001101010011001000110111011110010101000110011010101101010101000010010110101111011100...
output:
30001
result:
ok single line: '30001'
Test #24:
score: 0
Accepted
time: 5ms
memory: 11160kb
input:
1 1000000 11110001011010110101101101101001101100110001101000011100010010101010110000000111111010011101001110100001100011010111101000110110011000100100000001101110010011000111011110100100011011011101110001011010001011100000110110100000011010001111011111111000010000011000100101101000110000000001100101...
output:
20000
result:
ok single line: '20000'
Test #25:
score: 0
Accepted
time: 15ms
memory: 14020kb
input:
1 1000000 11110110100100101100010010101101010011010011000110111100000101011101000000110010101110100100101110111101001100010111010000110010100010101111001100111111100101100110111001100101000010011011011100111000011001001110110010110001001011110100010100111100101001101001010110011001011101011110111111...
output:
10000
result:
ok single line: '10000'
Test #26:
score: 0
Accepted
time: 14ms
memory: 11724kb
input:
1 1000000 10110110111011101100011011010100100110011110101101000100010110011111001110111100010111100101001101101111100101010100110011101000101101000010100100110101110001010100011011111001001011011110111010000000101100100010010100110010001101010110010011111101101111011011111000101100010100111001110111...
output:
5002
result:
ok single line: '5002'
Test #27:
score: 0
Accepted
time: 6ms
memory: 12152kb
input:
1 1000000 11011000001110011101010011011111101111000101001101000111000111000000110000000001000010001101110000110110101010011110110100011001101000010010101011000101000101111111011010100011010100000011101101010011110010100000111111010010011101010011100101001001011011011001111001111000110001101111001000...
output:
10
result:
ok single line: '10'
Test #28:
score: 0
Accepted
time: 0ms
memory: 6504kb
input:
1 100000 111110101000100010100110001101001111100000100010101001000000110111110010011111110011001100010100101001000000110010110110001001110001100000000110000000001110100000010001111010000001100011110111111100100010100111100101001100110011110100011011100111111000101110101101000011101011101111110001010...
output:
50000
result:
ok single line: '50000'
Test #29:
score: 0
Accepted
time: 10ms
memory: 9048kb
input:
1 1000000 10100000111001011000001111001101011111100001011101011001110001000001111011001101000110111010000111100011111100001100111101101001101101111010111110011100001111100100101100101000000110000110001101011000011100000111001001111100100000011011000101100001000000111001101010000010111000110100101100...
output:
500001
result:
ok single line: '500001'
Test #30:
score: 0
Accepted
time: 5ms
memory: 9192kb
input:
1 1000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
500002
result:
ok single line: '500002'
Test #31:
score: 0
Accepted
time: 3ms
memory: 4540kb
input:
1 500000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
146513
result:
ok single line: '146513'
Test #32:
score: 0
Accepted
time: 4ms
memory: 11236kb
input:
1 1000000 11111010101001011110111001010011100110100111111101110101110110111010010001111111001101111100010011111111011011001101011001101001101111010010111111110110111011101011010001001011000010110110101011110111111011101111001010100011011110111110111110100111101010110010111101111100111111011111110110...
output:
500000
result:
ok single line: '500000'
Test #33:
score: 0
Accepted
time: 10ms
memory: 8420kb
input:
1 1000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
500000
result:
ok single line: '500000'