QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#847198 | #8832. Daily Disinfection | yzhang | WA | 2ms | 3644kb | C++23 | 1.0kb | 2025-01-07 18:46:01 | 2025-01-07 18:46:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int T;
int n;
string s;
int len[200005],cntl;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>T;
while(T--){
cin>>n>>s;
int cnt=0;
for(int i=0;i<n;++i) if(s[i]=='1') ++cnt;
if(s[0]=='0'||s[n-1]=='0'){
cout<<cnt<<'\n';
}else{
bool fl=0;
for(int i=0;i+1<n;++i)
if(s[i]=='0'&&s[i+1]=='0')
fl=1;
if(fl) cout<<cnt<<'\n';
else{
cntl=0;
for(int i=0,j=i;i<n;i=j+1){
if(s[i]=='1'){
j=i;
while(j+1<n&&s[j+1]=='1') ++j;
len[++cntl]=j-i+1;
}else j=i;
}
int del1=min(len[1],len[2]);
int del2=min(len[cntl-1],len[cntl]);
int del=min(del1,del2);
cout<<cnt+del<<'\n';
}
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
input:
3 2 01 5 00110 9 101010101
output:
1 2 6
result:
ok 3 number(s): "1 2 6"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3644kb
input:
10000 15 010111111011011 10 1000101111 10 0011111101 1 0 3 110 4 1000 8 10000111 20 00000101000100001110 13 1101110110110 13 0111100011010 17 00001001111110101 1 0 20 10001010011000111100 11 00100110101 11 10110101000 15 001011110011000 16 1110111110000111 15 011110110110010 1 0 20 10110001101100010...
output:
11 6 7 0 2 1 4 6 9 7 9 0 9 5 5 7 11 9 0 9 8 7 3 6 0 6 2 5 4 8 10 4 6 1 7 2 1 8 1 8 11 9 13 4 11 13 16 6 4 4 5 1 1 7 7 5 3 0 0 11 8 5 6 7 6 4 9 1 4 5 12 0 2 10 4 3 7 7 3 7 4 3 7 9 15 2 6 6 9 8 6 1 2 6 2 11 10 5 0 0 4 7 4 7 0 4 7 9 3 3 10 3 6 11 8 1 8 6 5 2 4 9 7 1 5 7 8 3 5 11 6 10 8 8 9 16 2 7 6 4 3...
result:
ok 10000 numbers
Test #3:
score: 0
Accepted
time: 2ms
memory: 3584kb
input:
10000 15 011000111111100 13 1101010000010 16 0010000011101101 17 00111000100111101 3 101 19 1111101000101001001 13 0011101011111 11 10011100010 12 010101010001 2 01 13 1110010011111 12 101010001000 2 10 19 1010011010011011011 2 01 3 101 8 01001110 5 00111 20 10100010100101111101 15 010110011100010 3...
output:
9 5 7 9 3 10 9 5 5 1 9 4 1 11 1 3 4 3 11 7 1 3 0 4 7 5 4 5 7 11 9 10 3 6 3 12 5 8 10 8 0 5 6 9 4 0 10 4 5 9 8 5 9 4 10 9 11 2 9 9 9 5 5 7 2 3 5 2 10 9 3 12 5 9 4 0 2 8 7 1 11 9 6 2 8 7 6 5 7 7 12 2 7 3 3 11 5 7 2 1 15 1 5 7 8 4 10 7 1 9 2 3 9 7 11 4 4 4 8 5 3 0 8 3 2 2 8 1 3 7 8 7 3 0 6 4 7 0 1 0 5 ...
result:
ok 10000 numbers
Test #4:
score: -100
Wrong Answer
time: 2ms
memory: 3628kb
input:
10000 3 101 11 11101111011 7 1111001 2 01 8 10101010 20 11010101000011101010 2 10 9 000000000 15 010010100001110 20 01000000111101010010 19 0110001000100000000 17 01011011011100001 17 11010011000101000 18 001110110101011101 11 01010110011 4 1001 13 0011011101101 12 110010100011 18 001111011101110001...
output:
3 11 5 1 4 10 1 0 6 8 4 9 7 11 6 2 8 6 11 7 2 6 4 6 4 7 4 3 9 0 12 0 1 2 10 6 5 1 10 3 7 6 7 6 10 1 0 5 4 8 4 1 8 5 5 1 4 12 4 4 2 3 7 9 8 4 10 3 1 0 1 6 2 7 3 9 8 2 5 2 3 6 12 2 5 6 2 0 3 4 7 5 1 0 2 4 6 3 7 0 2 0 7 1 4 1 5 4 2 1 0 4 4 10 9 0 2 7 5 5 1 6 7 12 9 10 5 5 6 4 2 12 6 1 4 3 4 7 2 1 6 1 7...
result:
wrong answer 3263rd numbers differ - expected: '15', found: '16'