-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathA.cpp
85 lines (71 loc) · 1.4 KB
/
A.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
74
75
76
77
78
79
80
81
82
83
84
85
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sl(val) scanf("%lld", &val)
#define inf 2e18
int main()
{
ll n;
sl(n);
string s;
cin >> s;
if(n == 1) {
if(s == "1") {
printf("Yes\n");
return 0;
}
else {
printf("No\n");
return 0;
}
}
if(n == 2) {
if(s == "10" || s == "01") {
printf("Yes\n");
return 0;
}
else {
printf("No\n");
return 0;
}
}
bool chk = 1;
ll prv;
for(ll i = 0; i < s.length(); i++) {
if(i > 0) {
ll tmp = s[i] - '0';
if(tmp == prv && prv == 1) {
chk = 0;
break;
}
}
prv = s[i] - '0';
}
if(!chk) {
printf("No\n");
return 0;
}
bool checker = 1;
for(ll i = 1; i < s.length() - 1; i++) {
prv = s[i - 1] - '0';
ll now = s[i] - '0';
ll nxt = s[i + 1] - '0';
if(prv == 0 && now == 0 && nxt == 0) {
checker = 0;
break;
}
}
if(s[ s.length() - 1] == '0' && s[ s.length() - 2] == '0') {
checker = 0;
}
if(s[0] == '0' && s[1] == '0') {
checker = 0;
}
if(checker) {
printf("Yes\n");
}
else {
printf("No\n");
}
return 0;
}