-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path982A. Row.cpp
59 lines (50 loc) · 897 Bytes
/
982A. Row.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
/*
Idea:
- Brute force.
- Try to put 1 in each index i if and only if s[i] equal to 0 and check the
string.
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
if(n == 1) {
if(s == "0")
cout << "NO" << endl;
else
cout << "YES" << endl;
return 0;
}
if(n == 2) {
if(s == "00" || s == "11")
cout << "NO" << endl;
else
cout << "YES" << endl;
return 0;
}
for(int j = 1; j < n; ++j)
if(s[j] == s[j-1] && s[j] == '1') {
cout << "No" << endl;
return 0;
}
for(int i = 0; i < n; ++i) {
if(s[i] == '0') {
s[i] = '1';
bool ok = true;
for(int j = 1; j < n; ++j)
if(s[j] == s[j-1] && s[j] == '1') {
ok = false;
break;
}
s[i] = '0';
if(ok) {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
return 0;
}