-
Notifications
You must be signed in to change notification settings - Fork 0
/
Single operation part october challange
118 lines (100 loc) · 2.82 KB
/
Single operation part october challange
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
Problem
Chef has the binary representation SS of a number XX with him. He can modify the number by applying the following operation exactly once:
Make X := X \oplus \lfloor \frac{X}{2^{Y}} \rfloorX:=X⊕⌊
2
Y
X
⌋, where (1 \leq Y \leq |S|)(1≤Y≤∣S∣) and \oplus⊕ denotes the bitwise XOR operation.
Chef wants to maximize the value of XX after performing the operation. Help Chef in determining the value of YY which will maximize the value of XX after the operation.
Input Format
The first line of input will contain a single integer TT, denoting the number of test cases.
Each test case consists of two lines of inputs - the first containing the length of binary string SS.
The second line of input contains the binary string SS.
Output Format
For each test case, output on a new line, the value of YY which will maximize the value of XX after the operation.
Constraints
1 \leq T \leq 5 \cdot 10^41≤T≤5⋅10
4
1 \leq |S| \leq 10^51≤∣S∣≤10
5
The sum of |S|∣S∣ over all test cases won't exceed 5 \cdot 10^55⋅10
5
.
SS contains the characters 00 and 11 only.
Sample 1:
Input
Output
4
2
10
2
11
3
101
3
110
1
2
1
2
Explanation:
Test case 11: Since S = 10S=10 is the binary representation of 22, the current value of X = 2X=2. On choosing Y = 1Y=1, XX becomes 2 \oplus \lfloor \frac{2}{2^{1}} \rfloor = 32⊕⌊
2
1
2
⌋=3. We can show that this is the maximum value of XX we can achieve after one operation.
Test case 22: Since S = 11S=11 is the binary representation of 33, the current value of X = 3X=3. On choosing Y = 2Y=2, XX becomes 3 \oplus \lfloor \frac{3}{2^{2}} \rfloor = 33⊕⌊
2
2
3
⌋=3. We can show that this is the maximum value of XX we can achieve after one operation.
Test case 33: Since S = 101S=101 is the binary representation of 55, the current value of X = 5X=5. On choosing Y = 1Y=1, XX becomes 5 \oplus \lfloor \frac{5}{2^{1}} \rfloor = 75⊕⌊
2
1
5
⌋=7. We can show that this is the maximum value of XX we can achieve after one operation.
Test case 44: Since S = 110S=110 is the binary representation of 66, the current value of X = 6X=6. On choosing Y = 2Y=2, XX becomes 6 \oplus \lfloor \frac{6}{2^{2}} \rfloor = 76⊕⌊
2
2
6
⌋=7. We can show that this is the maximum value of XX we can achieve after one operation.
accepted
Accepted
236
total-Submissions
Submissions
1602
accuracy
Accuracy
15.86
answer:
#include <stdio.h>
int main(void)
{
int t;
scanf("%d",&t);
while(t--)
{
int l, count = 0;
scanf("%d",&l);
char str[l];
scanf("%s",str);
for(int i = 0;str[i]!='\0';i++)
{
if(str[i]=='1')
{
count++;
}
else{
break;
}
}
printf("%d\n",count);
}
return 0;
}