-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeforces1244B.cpp
More file actions
42 lines (42 loc) · 849 Bytes
/
Codeforces1244B.cpp
File metadata and controls
42 lines (42 loc) · 849 Bytes
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
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i,j,t,p,q,n,m;
cin>>t;
while(t--)
{
string x;
cin>>n>>x;
if(x[0]=='1' || x[n-1]=='1')
{
cout<<2*n<<endl;
}
else
{
p=-1,q=-1;
for(i=0;i<n;i++)
{
if(x[i]=='1')
{
p=i;
break;
}
}
if(p==-1)
{
cout<<n<<endl;
continue;
}
for(i=n-1;i>=0;i--)
{
if(x[i]=='1')
{
q=i;
break;
}
}
cout<<max((n-p)*2,(q+1)*2)<<endl;
}
}
}