-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeForces-1244B.cpp
More file actions
56 lines (54 loc) · 1.38 KB
/
CodeForces-1244B.cpp
File metadata and controls
56 lines (54 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// Created by abdob on 10/29/2022.
//
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
using namespace std;
int main()
{
fastread();
//freopen("input.txt","r", stdin);
ll t,n,a[1001];
cin>>t;
while(t--){
string s;
cin>>n>>s;
for(int i=0; i<n; i++){
a[i] = s[i] - '0';
}
if(a[0] == 1 || a[n-1] == 1){
cout<<n*2<<endl;
}
else{
int one = 0,leftVisit = 0,rightVisit = 0,ans = 0;
for(int i=0; i<n; i++){
if(a[i] == 1){
one = 1;
leftVisit = i;
break;
}
}
int i = -1;
for(int j=n-1; j>=0; j--){
i++;
if(a[j] == 1){
one = 1;
rightVisit = i;
break;
}
}
//cout<<leftVisit<<" "<<rightVisit<<endl;
ans = 2 * (n - min(leftVisit,rightVisit));
if(one == 0){
cout<<n<<endl;
}
else{
cout<<ans<<endl;
}
}
}
return 0;
}