-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbj_14503.cpp
More file actions
64 lines (54 loc) · 1.33 KB
/
bj_14503.cpp
File metadata and controls
64 lines (54 loc) · 1.33 KB
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
#include <iostream>
#include <string.h>
using namespace std;
int direc[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
// 0->북쪽, 1->동쪽, 2->남쪽 3->서쪽
int N, M, r, c;
int cnt = 0;
int map[51][51] = {};
int visit[51][51] = {};
void clean(int r, int c, int d) {
// for(int i = 0; i<N; i++) {
// for(int j = 0; j<M; j++) {
// cout << map[i][j] << " ";
// } cout << "\n";
// } cout << "\n";
if(map[r][c] == 0) {
map[r][c] = 2;
cnt++;
}
int xpos = r;
int ypos = c;
int next_d = d;
for(int i=0; i<4; i++) {
next_d = (next_d > 0) ? next_d-1 : 3; //왼쪽 방향
xpos = r + direc[next_d][0];
ypos = c + direc[next_d][1];
if(xpos >= 0 && xpos < N && ypos >= 0 && ypos < M && map[xpos][ypos] == 0) {
clean(xpos, ypos, next_d);
return;
}
}
int back_d = (d >= 2) ? d-2 : d+2;
xpos = r + direc[back_d][0];
ypos = c + direc[back_d][1];
if(xpos >= 0 && xpos < N && ypos >= 0 && ypos < M && map[xpos][ypos] != 1) {
clean(xpos, ypos, d);
}
return;
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int d;
cin >> N >> M;
cin >> r >> c >> d;
for(int i=0; i<N; i++) {
for(int j=0; j<M; j++) {
cin >> map[i][j];
}
}
clean(r, c, d);
cout << cnt << endl;
return 0;
}