forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfroggie.cpp
106 lines (87 loc) · 1.79 KB
/
froggie.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
#include <bits/stdc++.h>
using namespace std;
int l, w;
bool inrange(int x, int y) {
return x >= 0 && y >= 0 && x < w && y < l;
}
struct car {
int offset;
int interval;
int speed;
bool goingleft;
};
bool squished(int x, int t, car c) {
if(c.goingleft) {
x = w - x - 1;
}
t--;
// Get where the first car was
int actualpos = c.offset;
actualpos += (t * c.speed);
// Now there should be cars 'interval' apart
while(actualpos < w) {
actualpos += c.interval;
}
while(actualpos >= x) {
actualpos -= c.interval;
}
// If it's stopped, check this pos
if(c.speed == 0) {
if(x == actualpos + c.interval) return true;
return false;
}
// Otherwise, check where it will be
int loextra = min(1, c.speed);
int hiextra = c.speed;
if(actualpos + loextra <= x && x <= actualpos + hiextra) {
return true;
}
return false;
}
int main() {
cin >> l >> w;
vector<car> v;
for(int i = 0; i < l; i++) {
car c;
cin >> c.offset >> c.interval >> c.speed;
c.goingleft = (i%2 == 1);
v.push_back(c);
}
int x, y;
cin >> x;
y = -1;
bool safe = true;
string s;
cin >> s;
int t = 0;
for(auto i : s) {
t++;
if(i == 'L') {
x--;
}
if(i == 'R') {
x++;
}
if(i == 'U') {
y++;
}
if(i == 'D') {
y--;
}
if(y >= l) {
break;
}
if(inrange(x, y)) {
if(squished(x, t, v[l-y-1])) {
safe = false;
}
}
}
if(y < l) safe = false;
if(safe) {
cout << "safe" << endl;
}
else {
cout << "squish" << endl;
}
}