| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 857164 | Trisanu_Das | Nautilus (BOI19_nautilus) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int r, c, m, dp[100][100][100], res[100][100];
char a[100][100];
string s;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
void dfs(int x, int y, int far) {
if(!(0 <= x && x < r && 0 <= y && y < c && a[x][y] == '.')) return;
if(far == m) {
res[x][y] = 1; return;
}
if(dp[x][y][far]) return;
dp[x][y][far] = 1;
if(s[far] == 'E') dfs(x, y + 1, far + 1);
else if(s[far] == 'W') dfs(x, y - 1, far + 1);
else if(s[far] == 'N') dfs(x - 1, y, far + 1);
else if(s[far] == 'S') dfs(x + 1, y, far + 1);
else for(int i = 0; i < 4; i++) dfs(x + dx[i], y + dy[i], far + 1);
}
int main() {
cin >> r >> c >> m;
for(int i = 0; i < n; i++) cin >> a[i];
cin >> s;
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) if(a[i][j] == '.') dfs(i, j, 0);
int ans = 0;
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) if(a[i][j]) ans++;
cout << ans << '\n';
}
