-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_TRUE_Battle.cpp
More file actions
41 lines (34 loc) · 855 Bytes
/
A_TRUE_Battle.cpp
File metadata and controls
41 lines (34 loc) · 855 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
// we have a boolean string
// alice wants the output to be true
// bob wants to make it false
// print yes if alice wins else no
// so if 1st or last element is 1 she can always win or else she needs to have consecutive 1s
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool AliceWins(string &s){
ll n = s.size();
if (s[0] == '1' || s[n - 1] == '1') {
return true;
}
for (ll i = 1; i < n; i++) {
if (s[i] == '1' && s[i - 1] == '1') {
return true;
}
}
return false;
}
int main(){
ll testcases;
cin >> testcases;
for (ll testcase = 0; testcase < testcases; testcase++){
ll n;
cin >> n;
string s;
cin >> s;
if(AliceWins(s))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}