Skip to content

Commit b57b5ad

Browse files
authored
Merge pull request #529 from AlgorithmWithGod/khj20006
[20250723] BOJ / P4 / 직사각형 만들기 / 권혁준
2 parents ad386af + f32c05f commit b57b5ad

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
class IOController {
6+
BufferedReader br;
7+
BufferedWriter bw;
8+
StringTokenizer st;
9+
10+
public IOController() {
11+
br = new BufferedReader(new InputStreamReader(System.in));
12+
bw = new BufferedWriter(new OutputStreamWriter(System.out));
13+
st = new StringTokenizer("");
14+
}
15+
16+
String nextLine() throws Exception {
17+
String line = br.readLine();
18+
st = new StringTokenizer(line);
19+
return line;
20+
}
21+
22+
String nextToken() throws Exception {
23+
while (!st.hasMoreTokens()) nextLine();
24+
return st.nextToken();
25+
}
26+
27+
int nextInt() throws Exception {
28+
return Integer.parseInt(nextToken());
29+
}
30+
31+
long nextLong() throws Exception {
32+
return Long.parseLong(nextToken());
33+
}
34+
35+
double nextDouble() throws Exception {
36+
return Double.parseDouble(nextToken());
37+
}
38+
39+
void close() throws Exception {
40+
bw.flush();
41+
bw.close();
42+
}
43+
44+
void write(String content) throws Exception {
45+
bw.write(content);
46+
}
47+
48+
}
49+
50+
public class Main {
51+
52+
static IOController io;
53+
54+
//
55+
56+
static int N;
57+
static int[] arr;
58+
static boolean[][][][] dp;
59+
60+
public static void main(String[] args) throws Exception {
61+
62+
io = new IOController();
63+
64+
init();
65+
solve();
66+
67+
io.close();
68+
69+
}
70+
71+
static void init() throws Exception {
72+
73+
N = io.nextInt();
74+
arr = new int[N];
75+
for(int i=0;i<N;i++) arr[i] = io.nextInt();
76+
dp = new boolean[71][71][71][71];
77+
78+
}
79+
80+
static void solve() throws Exception {
81+
82+
dp[0][0][0][0] = true;
83+
for(int i=0;i<N;i++) {
84+
boolean[][][][] ndp = new boolean[71][71][71][71];
85+
for(int a=0;a<=70;a++) for(int b=0;b<=70;b++) for(int c=0;c<=70;c++) for(int d=0;d<=70;d++) if(dp[a][b][c][d]){
86+
if(a+arr[i] <= 70) ndp[a+arr[i]][b][c][d] = true;
87+
if(b+arr[i] <= 70) ndp[a][b+arr[i]][c][d] = true;
88+
if(c+arr[i] <= 70) ndp[a][b][c+arr[i]][d] = true;
89+
if(d+arr[i] <= 70) ndp[a][b][c][d+arr[i]] = true;
90+
}
91+
for(int a=0;a<=70;a++) for(int b=0;b<=70;b++) for(int c=0;c<=70;c++) for(int d=0;d<=70;d++) {
92+
ndp[a][b][c][d] |= dp[a][b][c][d];
93+
}
94+
dp = ndp;
95+
96+
}
97+
int ans = -1;
98+
for(int i=1;i<=70;i++) for(int j=1;j<=70;j++) {
99+
if(dp[i][i][j][j]) ans = Math.max(ans, i*j);
100+
}
101+
io.write(ans + "\n");
102+
103+
}
104+
105+
}
106+
```

0 commit comments

Comments
 (0)