-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Dual_Trigger.cpp
73 lines (71 loc) · 1.73 KB
/
A_Dual_Trigger.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using namespace chrono;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long getRandomNumber(long long l, long long r) {return uniform_int_distribution<long long>(l, r)(rng);}
#define debug(x...) { cout << "(" << #x << ")" << " = ( "; PRINT(x); }
template <typename T1> void PRINT(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void PRINT(T1 t1, T2... t2) { cout << t1 << " , "; PRINT(t2...); }
#define all(v) (v).begin(), (v).end()
//(data type to be stored (pair,int,string,vector),"null_type"(specifically used for set),comparator,underlying tree,class denoting the policy for updating node invaraints)
typedef tree < pair<int,int>, null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update > pbds;
void solve();
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.setf(ios::fixed);
cout.precision(10);
int t;
cin >> t;
while (t--)
{
solve();
}
}
void solve()
{
int n;
cin>>n;
string s;
cin>>s;
if(n==1)
{
if(s[0]=='1')
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
}
return;
}
vector<int>v;
for(int i=0;i<n;i++)
{
if(s[i]=='1')
v.push_back(i+1);
}
int sz=(int)(v.size());
if(sz%2)
{
cout<<"NO"<<endl;
return;
}
int m=sz/2;
for(int i=0;i<m;i++)
{
int d=v[i+m]-v[i];
if(d<=1)
{
cout<<"NO"<<endl;
return;
}
}
cout<<"YES"<<endl;
}