This repository was archived by the owner on Dec 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBOJ14503.java
More file actions
71 lines (55 loc) · 1.78 KB
/
Copy pathBOJ14503.java
File metadata and controls
71 lines (55 loc) · 1.78 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
65
66
67
68
69
70
71
import java.util.Scanner;
public class BOJ14503 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int robotX = sc.nextInt();
int robotY = sc.nextInt();
int dir = sc.nextInt();
int[] xDir = new int[]{-1, 0, 1, 0};
int[] yDir = new int[]{0, 1, 0, -1};
int[][] map = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
map[i][j] = sc.nextInt();
}
}
while (true) {
if (map[robotX][robotY] == 0) {
map[robotX][robotY] = 2;
}
boolean allBlock = false;
for (int i = 0; i < 4; i++) {
dir = (dir + 3) % 4;
if (map[robotX + xDir[dir]][robotY + yDir[dir]] == 0) {
break;
}
else if (i == 3 && map[robotX + xDir[dir]][robotY + yDir[dir]] > 0) {
allBlock = true;
}
}
if (!allBlock) {
robotX += xDir[dir];
robotY += yDir[dir];
continue;
}
dir = (dir + 2) % 4;
if (map[robotX + xDir[dir]][robotY + yDir[dir]] == 1) {
break;
}
robotX += xDir[dir];
robotY += yDir[dir];
dir = (dir + 2) % 4;
}
int answer = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (map[i][j] == 2) {
answer++;
}
}
}
System.out.println(answer);
}
}