Skip to content

Commit 014ecda

Browse files
committed
[Silver II] Title: 숫자판 점프, Time: 160 ms, Memory: 17468 KB -BaekjoonHub
1 parent da0704a commit 014ecda

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# [Silver II] 숫자판 점프 - 2210
2+
3+
[문제 링크](https://www.acmicpc.net/problem/2210)
4+
5+
### 성능 요약
6+
7+
메모리: 17468 KB, 시간: 160 ms
8+
9+
### 분류
10+
11+
그래프 이론, 브루트포스 알고리즘, 그래프 탐색, 깊이 우선 탐색, 격자 그래프
12+
13+
### 제출 일자
14+
15+
2025년 8월 7일 18:54:57
16+
17+
### 문제 설명
18+
19+
<p>5×5 크기의 숫자판이 있다. 각각의 칸에는 숫자(digit, 0부터 9까지)가 적혀 있다. 이 숫자판의 임의의 위치에서 시작해서, 인접해 있는 네 방향으로 다섯 번 이동하면서, 각 칸에 적혀있는 숫자를 차례로 붙이면 6자리의 수가 된다. 이동을 할 때에는 한 번 거쳤던 칸을 다시 거쳐도 되며, 0으로 시작하는 000123과 같은 수로 만들 수 있다.</p>
20+
<p>숫자판이 주어졌을 때, 만들 수 있는 서로 다른 여섯 자리의 수들의 개수를 구하는 프로그램을 작성하시오.</p>
21+
22+
### 입력
23+
24+
<p>다섯 개의 줄에 다섯 개의 정수로 숫자판이 주어진다.</p>
25+
26+
### 출력
27+
28+
<p>첫째 줄에 만들 수 있는 수들의 개수를 출력한다.</p>
29+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
static int[][] board = new int[5][5];
6+
static int[] dx = {0,0,-1,1};
7+
static int[] dy = {1,-1,0,0};
8+
static Set<String> set = new HashSet<>();
9+
10+
public static void main(String[] args) throws IOException{
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
13+
for(int i=0; i<5; i++){
14+
StringTokenizer st = new StringTokenizer(br.readLine());
15+
for(int j=0; j<5; j++){
16+
board[i][j] = Integer.parseInt(st.nextToken());
17+
}
18+
}
19+
20+
for(int i=0; i<5; i++){
21+
for(int j=0; j<5; j++){
22+
dfs(i, j, 0, board[i][j]+"");
23+
}
24+
}
25+
26+
System.out.println(set.size());
27+
}
28+
29+
public static void dfs(int x, int y, int depth, String s){
30+
if(depth == 5){
31+
set.add(s);
32+
return;
33+
}
34+
for(int i=0; i<4; i++){
35+
int newX = x+dx[i];
36+
int newY = y+dy[i];
37+
38+
if(rangeCheck(newX, newY)){
39+
dfs(newX, newY, depth+1, s+board[newX][newY]);
40+
}
41+
}
42+
}
43+
44+
public static boolean rangeCheck(int x, int y){
45+
return x>=0 && y>=0 && x<5 && y<5;
46+
}
47+
}

0 commit comments

Comments
 (0)