-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_2450.java
More file actions
54 lines (41 loc) · 1.75 KB
/
Copy pathBOJ_2450.java
File metadata and controls
54 lines (41 loc) · 1.75 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
import java.io.*;
import java.util.*;
public class BOJ_2450 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int result = Integer.MAX_VALUE;
int n = Integer.parseInt(br.readLine());
int[] arr = new int[n];
int[] numCnt = new int[4];
st = new StringTokenizer(br.readLine());
for(int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
numCnt[arr[i]]++;
}
// 조합 만들기 - 6가지 경우
int[][] perm = {{1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1}};
for(int i = 0; i < 6; i++) {
int[] check = perm[i];
int[] combi = new int[n];
int idx = 0;
for (int num : check) {
Arrays.fill(combi, idx, idx + numCnt[num], num);
idx += numCnt[num];
}
// System.out.println("combi = " + Arrays.toString(combi));
// 지금 숫자 배열과 조합을 통해 만들어진 배열의 차이를 나타내는 map을 만들어보자
int[][] map = new int[4][4];
for(int k = 0; k < n; k++) {
if(arr[k] == combi[k]) continue;
map[combi[k]][arr[k]]++;
}
// System.out.println("map = " + Arrays.deepToString(map));
// 이 조합의 상황에서의 최소로 움직이는 횟수
int minMove = map[1][2] + map[1][3] + Math.max(map[2][3], map[3][2]);
// System.out.println("minMove = " + minMove);
result = Math.min(result, minMove);
}
System.out.println(result);
}
}