-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCC_LTALL.cpp
More file actions
31 lines (30 loc) · 1011 Bytes
/
CC_LTALL.cpp
File metadata and controls
31 lines (30 loc) · 1011 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
#include <bits/stdc++.h>
#define nl '\n'
using namespace std;
typedef long long ll;
// Author oGhostyyy
/* Thinking:n prison cells in a row, each cell has a light it can face left or right, can only light adjacent cell
light can lihgt up (i, i+1 / i, i-1) */
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt; cin >> tt;
while(tt--){
int n; cin >> n; //number of cells
string s; cin >> s; //binary string with light info
bool pos = true; //initially assume its possible
vector<bool> left(n,false); //assume its pointing right first
for(int i = 0; i < n; i++){
if(s[i] == '1') continue; //we can keep going
if(i > 0 && s[i -1] == '1' && !left[i-1]) continue;
if(i < n -1 && s[i+1] == '1'){
left[i+1] = true;
continue;
}
pos = false;
break;
}
if(pos) cout << "YES" << nl;
else cout << "NO" << nl;
}
}