-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaekjoon_2615.java
More file actions
84 lines (57 loc) · 1.73 KB
/
baekjoon_2615.java
File metadata and controls
84 lines (57 loc) · 1.73 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
import java.util.*;
import java.io.*;
public class baekjoon_2615 {
static int N = 19;
static final int B = 1, W = 2;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int[][] board = new int[N][N];
Queue<int[]> queue = new LinkedList<>();
for(int i=0;i<N;i++) {
st = new StringTokenizer(br.readLine());
for(int j=0;j<N;j++) {
board[i][j] = Integer.parseInt(st.nextToken());
if(board[i][j] > 0) queue.add(new int[]{i, j});
}
}
boolean fail = true;
while(!queue.isEmpty()) {
int[] cur = queue.poll();
int r = cur[0];
int c = cur[1];
if(check(r, c, board)) {
System.out.println(board[r][c]);
System.out.printf("%d %d\n", r+1, c+1);
fail = false;
break;
}
}
if(fail) System.out.println("0");
}
static boolean check(int r, int c, int[][] board) {
int color = board[r][c];
int[][] dir = {{0,1},{1,0},{1,1},{-1,1}};
for (int[] d : dir) {
int cnt = 0;
for (int i = 0; i < 5; i++) {
int nr = r + d[0] * i;
int nc = c + d[1] * i;
if (nr < 0 || nr >= 19 || nc < 0 || nc >= 19) break;
if (board[nr][nc] != color) break;
cnt++;
}
if (cnt == 5) {
int pr = r - d[0];
int pc = c - d[1];
int nr = r + d[0] * 5;
int nc = c + d[1] * 5;
if ((pr < 0 || pr >= 19 || pc < 0 || pc >= 19 || board[pr][pc] != color) &&
(nr < 0 || nr >= 19 || nc < 0 || nc >= 19 || board[nr][nc] != color)) {
return true;
}
}
}
return false;
}
}