Skip to content

Commit 63916e9

Browse files
authored
Merge pull request #894 from AlgorithmWithGod/0224LJH
[20250914] BOJ / G5 / 주사위 / 이종환
2 parents c2267f3 + 2fff095 commit 63916e9

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

0224LJH/202509/14 BOJ 주사위.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.*;
6+
7+
public class Main {
8+
9+
static StringBuilder sb = new StringBuilder();
10+
static long size, oneMax,twoMax,threeMax,ans;
11+
static Long[] num;
12+
13+
14+
public static void main(String[] args) throws NumberFormatException, IOException {
15+
init();
16+
process();
17+
print();
18+
}
19+
20+
public static void init() throws NumberFormatException, IOException {
21+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
22+
size = Integer.parseInt(br.readLine());
23+
num = new Long[6];
24+
StringTokenizer st = new StringTokenizer(br.readLine());
25+
for (int i = 0 ; i < 6 ; i++) {
26+
num[i] = Long.parseLong(st.nextToken());
27+
}
28+
29+
30+
}
31+
32+
public static void process() {
33+
34+
35+
getOneMax();
36+
getTwoMax();
37+
getThreeMax();
38+
39+
// System.out.println(oneMax);
40+
// System.out.println(twoMax);
41+
// System.out.println(threeMax);
42+
//
43+
ans = 0;
44+
45+
if (size == 1) {
46+
long max = 0;
47+
for (int i = 0; i < 6; i++) {
48+
max = Math.max(max, num[i]);
49+
ans += num[i];
50+
}
51+
ans -= max;
52+
return;
53+
}
54+
ans += ((size-2) * (size-1) * 4 + (size-2) * (size-2)) * oneMax;
55+
ans += ((size-1)*4 + (size-2)*4)* twoMax;
56+
ans += 4 * threeMax;
57+
58+
}
59+
60+
private static void getThreeMax() {
61+
threeMax = Long.MAX_VALUE;
62+
for (int i = 0; i < 6; i++) {
63+
for (int j = i+1; j < 6; j++) {
64+
for (int k = j+1; k < 6; k++) {
65+
Long n1 = num[i];
66+
Long n2 = num[j];
67+
Long n3 = num[k];
68+
69+
if (i + j == 5 || i + k == 5 || j + k == 5) continue;
70+
71+
threeMax = Math.min(threeMax, n1+n2+n3);
72+
}
73+
}
74+
}
75+
76+
}
77+
78+
private static void getTwoMax() {
79+
twoMax = Long.MAX_VALUE;
80+
for (int i = 0; i < 6; i++) {
81+
for (int j = i+1; j < 6; j++) {
82+
Long n1 = num[i];
83+
Long n2 = num[j];
84+
85+
if (i + j == 5) continue;
86+
87+
twoMax = Math.min(twoMax, n1+n2);
88+
}
89+
}
90+
91+
}
92+
93+
private static void getOneMax() {
94+
Long temp = Long.MAX_VALUE;
95+
for (int i = 0 ; i < 6; i++) {
96+
temp = Math.min(temp, num[i]);
97+
}
98+
oneMax = temp;
99+
}
100+
101+
public static void print() {
102+
System.out.println(ans);
103+
}
104+
}
105+
```

0 commit comments

Comments
 (0)