Closed yu-heejin closed 2 months ago
import java.io.; import java.util.;
public class Main { static int[][] board; public static void main(String args[]) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
board = new int[19][19];
String[] input;
for (int i = 0; i < 19; i++) {
input = br.readLine().split(" ");
for (int j = 0; j < 19; j++) {
board[i][j] = Integer.parseInt(input[j]);
}
}
}
// dfs - 스택오버플로우
private static boolean dfs(int x, int y, int depth, int color) {
if (x < 0 || x >= 19 || y < 0 || y >= 19) return false;
if (board[x][y] == 0) {
if (depth == 5) return true;
return false;
}
if (board[x][y] == color) depth++;
dfs(x - 1, y, depth, color); // 상
dfs(x + 1, y, depth, color); // 하
dfs(x, y - 1, depth, color); // 좌
dfs(x, y + 1, depth, color); // 우
dfs(x + 1, y + 1, depth, color); // 우하향
dfs(x + 1, y - 1, depth, color); // 좌하향
dfs(x - 1, y - 1, depth, color); // 좌상향
dfs(x - 1, y + 1, depth, color); // 우상향
return false;
}
}
https://www.acmicpc.net/problem/2615