#include <bits/stdc++.h>
using namespace std;
int r, c, m, ans;
char a[500][500];
string s;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
void paths(int x, int y, int far){
if(x < 0 || x >= r || y < 0 || y >= c || a[x][y] == '#') return;
if(far == m){
ans++; return;
}
if(s[far] == 'N') paths(x - 1, y, far + 1);
else if(s[far] == 'S') paths(x + 1, y, far + 1);
else if(s[far] == 'W') paths(x, y - 1, far + 1);
else if(s[far] == 'E') paths(x, y + 1, far + 1);
else for(int d = 0; d < 4; d++) paths(x + dx[d], y + dy[d], far + 1);
}
int main(){
cin >> r >> c >> m;
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) cin >> a[i][j];
cin >> s;
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) if(a[i][j] != '#') paths(i, j, 0);
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Execution timed out |
1043 ms |
348 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Execution timed out |
1043 ms |
348 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |