-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_1013.cpp
More file actions
85 lines (78 loc) · 1.37 KB
/
BOJ_1013.cpp
File metadata and controls
85 lines (78 loc) · 1.37 KB
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
// 21/10/22
// (100+1+ | 01)+
#include <iostream>
#include <string>
using namespace std;
int answer = 0;
string s;
void DFS(int i, int first, int state)
{
if ((int)s.size() == i)
{
if (state == 2)
return;
else if (state == 1)
return;
answer++;
return;
}
if (state == 0)
{
if (s[i] == '1')
DFS(i+1, i, 1);
else
DFS(i+1, i, 2);
}
else if (state == 2)
{
if (s[i] != '1')
return;
else
DFS(i+1, i+1, 0);
}
else if (state == 1)
{
if (i - first <= 2)
{
if (s[i] != '0')
return;
else
DFS(i+1, first, 1);
}
else
{
if (s[i] == '0')
DFS(i+1, first, 1);
else
DFS(i+1, first, 3);
}
}
else
{
if (s[i] == '1')
{
DFS(i+1, i, 1);
DFS(i+1, first, 3);
}
else
DFS(i+1, i, 2);
}
}
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int test_num;
cin >> test_num;
while (test_num--)
{
cin >> s;
answer = 0;
DFS(0, 0, 0);
if (answer)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}