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 pathBOJ3190.java
More file actions
87 lines (72 loc) · 2.35 KB
/
Copy pathBOJ3190.java
File metadata and controls
87 lines (72 loc) · 2.35 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.util.Arrays;
import java.util.Scanner;
public class BOJ3190 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[][] map = new int[n + 2][n + 2];
Arrays.fill(map[0], -1);
for (int i = 1; i <= n; i++) {
map[i][0] = -1;
map[i][n + 1] = -1;
}
Arrays.fill(map[n + 1], -1);
for (int i = 0; i < k; i++) {
map[sc.nextInt()][sc.nextInt()] = 1;
}
int l = sc.nextInt();
int[] move = new int[10001];
for (int i = 1; i <= l; i++) {
int Index = sc.nextInt();
char dir = sc.next().charAt(0);
if (dir == 'L') {
move[Index] = 3;
} else {
move[Index] = 1;
}
}
int[] xDir = new int[]{-1, 0, 1, 0};
int[] yDir = new int[]{0, 1, 0, -1};
int dir = 1;
int tailDir = 1;
int curX = 1;
int curY = 1;
int tailX = 1;
int tailY = 1;
int tailSec = 0;
map[1][1] = 2;
while (true) {
for (int i = 1; i <= 10000; i++) {
boolean eat = false;
switch (map[curX + xDir[dir]][curY + yDir[dir]]) {
case -1:
System.out.println(i);
return;
case 0:
map[curX + xDir[dir]][curY + yDir[dir]] = 2;
break;
case 1:
map[curX + xDir[dir]][curY + yDir[dir]] = 2;
eat = true;
break;
case 2:
System.out.println(i);
return;
}
curX += xDir[dir];
curY += yDir[dir];
dir = (dir + move[i]) % 4;
if (!eat) {
map[tailX][tailY] = 0;
tailX += xDir[tailDir];
tailY += yDir[tailDir];
tailDir = (tailDir + move[i - tailSec]) % 4;
}
else {
tailSec++;
}
}
}
}
}