-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14503.cpp
More file actions
58 lines (53 loc) · 1.22 KB
/
Copy path14503.cpp
File metadata and controls
58 lines (53 loc) · 1.22 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
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX =55;
int n,m, x,y,dir, ans=1;
int map[MAX][MAX];
bool visited[MAX][MAX];
bool flag =true;
int dxdy[4][2]= { {-1,0}, {0,1}, {1,0}, {0,-1}};
int main() {
//Please Enter Your Code Here
scanf("%d %d", &n, &m);
scanf("%d %d %d", &x, &y, &dir);
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
scanf("%d", &map[i][j]);
}
}
int dx,dy, tmp;
visited[x][y]=true;
while(flag){
flag=false;
// 4방향 청소할곳 확인
for(int i=dir+3; i>=dir; i--){
tmp = i%4;
dx = x + dxdy[tmp][0];
dy = y + dxdy[tmp][1];
if(dx>=0 and dy>=0 and dx<n and dy<m and map[dx][dy]==0 and !visited[dx][dy]){
// printf("%d %d %d\n", dx, dy, tmp);
x = dx;
y = dy;
dir = tmp;
flag=true;
ans++;
visited[dx][dy]=true;
break;
}
}
// 빠꾸
if(!flag){
dx = x - dxdy[dir][0];
dy = y - dxdy[dir][1];
if(dx>=0 and dy>=0 and dx<n and dy<m and map[dx][dy]==0){
x = dx;
y = dy;
flag=true;
}
}
}
printf("%d", ans);
return 0;
}