-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path1244 B.cpp
54 lines (45 loc) · 889 Bytes
/
1244 B.cpp
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
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pii pair <int, int>
#define pll pair <long long, long long>
using namespace std;
int t, n, l, r;
string s;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> t;
while(t--)
{
cin >> n;
cin >> s;
l = 0;
r = 0;
for(int i = 0; i < n; i++)
{
if(s[i] == '1')
{
r = i + 1;
}
}
for(int i = n - 1; i >= 0; i--)
{
if(s[i] == '1')
{
l = i + 1;
}
}
// cout << l << " " << r << "\n";
if(l != 0 && r != 0)
{
cout << max(n, max(2 * r, 2 * (n - l + 1))) << "\n";
}
else
{
cout << n << "\n";
}
}
}