QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#559002#8832. Daily DisinfectionAmanicus#WA 3ms3640kbC++14947b2024-09-11 19:38:102024-09-11 19:38:14

Judging History

你现在查看的是最新测评结果

  • [2024-09-11 19:38:14]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3640kb
  • [2024-09-11 19:38:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define llt __int128_t
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 1e2+10;
const int M = 1e6 + 7;
const int MAX = 0x3f3f3f3f;
const ll maxn = 1e18;
ll h,s1,vv,u,mi,mx,fz,fm,ans,item,f;
ll m,n,x,y,x2,y2,z,z2,d,gcd,l,r,k,T,p,cnt;
ll sum;
ll c[M],dp[N][N];
string s,ss,s3,s2;
ll a[N];
map<char,ll>mp;
void solve() {
	cin>>n;
	cin>>s;
	l=-1;
	r=0;
	f=1;
	for(ll i=0;i<n;i++){
		if(s[i]=='1'){
			r++;
		}
		else{
			if(r-l==0){
				f=0;
			}
			l=i;
			r=l;
		}
	}
	l=0;
	ll ans=0;
	ll mn=1e10;
	for(ll i=0;i<n;i++){
		if(s[i]=='1'){
			ans++;
			l++;
		}
		else if(l>0){
			mn=min(mn,l);
		}
	}
	if(l>0){
		mn=min(mn,l);
	}
	if(f==1&&s[0]=='1'&&s[n-1]=='1'){
		cout<<ans+mn<<"\n";
	}
	else{
		cout<<ans<<"\n";
	}
}
int main() {
	IOS;
	T=1;
	cin>>T;
	while(T--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

input:

3
2
01
5
00110
9
101010101

output:

1
2
6

result:

ok 3 number(s): "1 2 6"

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3640kb

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
9
11
9
13
4
11
13
19
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
5
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
13
6
5
2
4
9
7
1
5
7
8
3
5
11
6
10
8
8
9
16
2
7
6
4
...

result:

wrong answer 40th numbers differ - expected: '8', found: '9'