-
Notifications
You must be signed in to change notification settings - Fork 185
/
00118.cc
61 lines (61 loc) · 1.22 KB
/
00118.cc
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
// https://uva.onlinejudge.org/external/1/118.pdf
#include<bits/stdc++.h>
using namespace std;
using vb=vector<bool>;
using vvb=vector<vb>;
int main(){
int X,Y,x,y;
char o;
string s;
cin>>X>>Y;
vvb a(X+1, vb(Y+1));
while(cin>>x>>y>>o>>s){
bool l=0;
for(auto c:s){
if(c=='R'){
if(o=='N')o='E';
else if(o=='E')o='S';
else if(o=='S')o='W';
else o='N';
}else if(c=='L'){
if(o=='N')o='W';
else if(o=='E')o='N';
else if(o=='S')o='E';
else o='S';
}else{
if(o=='N'){
if(y==Y){
if(!a[x][y]){
a[x][y]=1;
l=1;
break;
}
}else y++;
}else if(o=='E'){
if(x==X){
if(!a[x][y]){
a[x][y]=1;
l=1;
break;
}
}else x++;
}else if(o=='S'){
if(y==0){
if(!a[x][y]){
l=1;
break;
}
}else y--;
}else{
if(x==0){
if(!a[x][y]){
l=1;
break;
}
}else x--;
}
}
}
printf("%d %d %c%s\n",x,y,o,l?" LOST":"");
}
}