-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday17-part1.cpp
137 lines (135 loc) · 2.36 KB
/
day17-part1.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
const int mx=1e6+6;// 1000000
int a[mx][9];
string s;
int n;
int idx;
int low;
int res;
void go(vector <pair<int,int> > v,bool str){ // do string
idx = idx%n;
if(str == true){
bool check = true;
for(auto t:v){
int x = t.first;
int y = t.second;
if(s[idx]=='>'){
if(a[x][y+1]==1)check = false;
}
else if(s[idx]=='<'){
if(a[x][y-1]==1)check = false;
}
}
if(check == true){
vector <pair<int,int> > p;
for(auto t:v){
int x = t.first;
int y = t.second;
if(s[idx]=='>'){
p.pb({x,y+1});
}
else if(s[idx]=='<'){
p.pb({x,y-1});
}
}
idx++;
go(p,!str);
}
else if(check == false){
idx++;
go(v,!str);
return;
}
}
else if(str == false){ // move down
bool check = true;
for(auto t:v){
int x = t.first;
int y = t.second;
if(a[x-1][y]==1){
check = false;
}
}
if(check == true){
vector <pair<int,int> > p;
for(auto t:v){
int x = t.first;
int y = t.second;
p.push_back({x-1,y});
}
go(p,!str);
}
else if(check == false){
for(auto t:v){
int x = t.first;
int y = t.second;
a[x][y] = 1;
low = max(low,x);
}
return;
}
}
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin >> s;
n = s.length();
for(int i=0;i<mx;i++){
for(int j=0;j<9;j++){
if(i==0 or j==0 or j==8)
a[i][j] = 1;
}
}
low = 0;
for(res=0;res<134;res++){
cout << res << ": " << low << endl;
if(res%5==0){
vector <pair<int,int> > v;
v.pb({low+4,3});
v.pb({low+4,4});
v.pb({low+4,5});
v.pb({low+4,6});
go(v,true);
}
else if(res%5==1){
vector <pair<int,int> > v;
v.pb({low+4,4});
v.pb({low+5,3});
v.pb({low+5,4});
v.pb({low+5,5});
v.pb({low+6,4});
go(v,true);
}
else if(res%5==2){
vector <pair<int,int> > v;
v.pb({low+4,3});
v.pb({low+4,4});
v.pb({low+4,5});
v.pb({low+5,5});
v.pb({low+6,5});
go(v,true);
}
else if(res%5==3){
vector <pair<int,int> > v;
v.pb({low+4,3});
v.pb({low+5,3});
v.pb({low+6,3});
v.pb({low+7,3});
go(v,true);
}
else if(res%5==4){
vector <pair<int,int> > v;
v.pb({low+4,3});
v.pb({low+4,4});
v.pb({low+5,3});
v.pb({low+5,4});
go(v,true);
}
}
cout << low << endl;
}