-
Notifications
You must be signed in to change notification settings - Fork 0
/
908B New Year and Buggy Bot.cpp
executable file
·159 lines (141 loc) · 2.28 KB
/
908B New Year and Buggy Bot.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct pointer
{
int i;
int j;
};
pointer Down(pointer a)
{
a.i++;
return a;
}
pointer Right(pointer a)
{
a.j++;
return a;
}
pointer Up(pointer a)
{
a.i--;
return a;
}
pointer Left(pointer a)
{
a.j--;
return a;
}
int direction(vector<string> &maze,int n,int m,pointer start,pointer end,string ans)
{
string keys="DLRU";
char c1,c2,c3,c4;
int count=0;
int found;
for(int keys_i=1;keys_i<25;keys_i++)
{
c1=keys[0];
c2=keys[1];
c3=keys[2];
c4=keys[3];
pointer st=start;
found=1;
for(int j=0;j<ans.length()&&found;j++)
{
if(ans[j]=='0')
{
if(c1=='D')
st=Down(st);
else if(c1=='L')
st=Left(st);
else if(c1=='R')
st=Right(st);
else
st=Up(st);
}
else if(ans[j]=='1')
{
if(c2=='D')
st=Down(st);
else if(c2=='L')
st=Left(st);
else if(c2=='R')
st=Right(st);
else
st=Up(st);
}
else if(ans[j]=='2')
{
if(c3=='D')
st=Down(st);
else if(c3=='L')
st=Left(st);
else if(c3=='R')
st=Right(st);
else
st=Up(st);
}
else
{
if(c4=='D')
st=Down(st);
else if(c4=='L')
st=Left(st);
else if(c4=='R')
st=Right(st);
else
st=Up(st);
}
if(st.i<0||st.i>=n)
{
found=0;
}
else if(st.j<0||st.j>=m)
{
found=0;
}
else if(maze[st.i][st.j]=='#')
{
found=0;
}
else if(maze[st.i][st.j]=='E')
{
count++;
found=0;
}
}
next_permutation(keys.begin(),keys.end());
}
return count;
}
int main()
{
pointer start,end;
int n,m;
cin >> n >> m;
vector<string> maze(n);
for(int i=0;i<n;i++)
{
cin >> maze[i];
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(maze[i][j]=='S')
{
start.i=i;
start.j=j;
}
else if(maze[i][j]=='E')
{
end.i=i;
end.j=j;
}
}
}
string s;
cin >> s;
cout << direction(maze,n,m,start,end,s);
return 0;
}