Skip to content

Commit dc3f607

Browse files
committed
[Simulation] swea-2115
1 parent 2b96490 commit dc3f607

File tree

5 files changed

+160
-0
lines changed

5 files changed

+160
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
| 28 | ⭐️ | [SWEA-5656 벽돌 깨기](./src/Simulation/swea5656) | |
6868
| 29 | | [Baekjoon-17406 배열 돌리기 4](./src/Simulation/P17406) | |
6969
| 30 | | [SWEA-9760 Poker Game](./src/Simulation/swea9760) | |
70+
| 31 | | [SWEA-2115 벌꿀채취](./src/Simulation/swea2115) | |
7071

7172
## String
7273

src/Simulation/swea2115/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## [SW Expert Academy - 2115] 벌꿀채취
2+
3+
![image](https://user-images.githubusercontent.com/22045163/115662923-a8e74b00-a37a-11eb-8543-5e7fe9010a9d.png)
4+
![image](https://user-images.githubusercontent.com/22045163/115662963-b3094980-a37a-11eb-89c3-16c47c470ebc.png)
5+
![image](https://user-images.githubusercontent.com/22045163/115662989-bdc3de80-a37a-11eb-91b0-a1dcf8031160.png)
6+
7+
![image](https://user-images.githubusercontent.com/22045163/115663026-cae0cd80-a37a-11eb-9c9e-3d275d11c79d.png)

src/Simulation/swea2115/Solution.java

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package Simulation.swea2115;
2+
3+
import java.io.*;
4+
import java.util.*;
5+
6+
public class Solution {
7+
8+
static int T, N, M, C;
9+
static int[][] map;
10+
static int[] select;
11+
12+
public static void main(String[] args) throws Exception {
13+
System.setIn(new FileInputStream("src/Simulation/swea2115/sample_input.txt"));
14+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
15+
StringBuilder sb = new StringBuilder();
16+
17+
T = Integer.parseInt(br.readLine());
18+
for (int t = 1; t <= T; t++) {
19+
StringTokenizer st = new StringTokenizer(br.readLine());
20+
N = Integer.parseInt(st.nextToken());
21+
M = Integer.parseInt(st.nextToken());
22+
C = Integer.parseInt(st.nextToken());
23+
24+
map = new int[N][N];
25+
for (int i = 0; i < N; i++) {
26+
st = new StringTokenizer(br.readLine());
27+
for (int j = 0; j < N; j++) {
28+
map[i][j] = Integer.parseInt(st.nextToken());
29+
}
30+
}
31+
32+
int rcnt = N-M+1;
33+
select = new int[N*rcnt];
34+
for (int i = 0, cnt = 0; i < N; i++) {
35+
for (int j = 0; j < rcnt; j++) {
36+
select[cnt++] = collect(i, j);
37+
}
38+
}
39+
40+
int ans = 0;
41+
for (int i = 0, size = N*rcnt, r = rcnt; i < size; i++) {
42+
int j = i+M;
43+
for (; j < r; j++) ans = Math.max(ans, select[i] + select[j]);
44+
for (j = r; j < size; j++) ans = Math.max(ans, select[i] + select[j]);
45+
if (i == r-1) r += rcnt;
46+
}
47+
48+
sb.append("#").append(t).append(" ").append(ans).append("\n");
49+
}
50+
51+
System.out.println(sb.toString());
52+
}
53+
54+
static int collect(int i, int j) {
55+
int res = 0;
56+
int[] sub = Arrays.copyOfRange(map[i], j, j+M);
57+
Arrays.sort(sub);
58+
for (int flag = 1; flag < 1<<M; flag++) {
59+
int amt = 0;
60+
for (int k = M-1, c = 0; k >= 0; k--) {
61+
if ((flag & 1<<k) != 0) {
62+
c += sub[k];
63+
if (c > C) break;
64+
amt += sub[k]*sub[k];
65+
}
66+
}
67+
res = Math.max(res, amt);
68+
}
69+
return res;
70+
}
71+
}
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
10
2+
4 2 13
3+
6 1 9 7
4+
9 8 5 8
5+
3 4 5 3
6+
8 2 6 7
7+
3 3 10
8+
7 2 9
9+
6 6 6
10+
5 5 7
11+
4 1 10
12+
8 1 8 2
13+
4 6 1 6
14+
4 9 6 3
15+
7 4 1 3
16+
4 3 12
17+
8 8 6 5
18+
5 2 7 4
19+
8 5 1 7
20+
7 8 9 4
21+
5 2 11
22+
7 5 9 9 6
23+
7 3 7 9 3
24+
1 7 1 4 5
25+
1 7 9 2 6
26+
6 6 8 3 8
27+
6 3 20
28+
8 5 2 4 3 1
29+
4 3 6 1 1 8
30+
4 4 1 2 3 1
31+
1 7 4 9 6 1
32+
6 5 1 2 8 4
33+
3 1 4 5 1 3
34+
7 2 11
35+
2 8 2 5 2 8 6
36+
2 3 7 4 6 4 8
37+
3 7 8 3 9 4 4
38+
8 8 5 9 3 6 9
39+
9 7 6 2 4 1 3
40+
2 9 2 8 9 7 3
41+
2 1 7 2 7 8 3
42+
8 3 12
43+
9 1 6 7 5 4 6 7
44+
9 5 1 8 8 3 5 8
45+
5 2 6 8 6 9 2 1
46+
9 2 1 8 7 5 2 3
47+
6 5 5 1 4 5 7 2
48+
1 7 1 8 1 9 5 5
49+
6 2 2 9 2 5 1 4
50+
7 1 1 2 5 9 5 7
51+
9 4 20
52+
5 2 4 8 3 7 6 2 1
53+
7 9 8 5 8 2 6 3 6
54+
1 9 4 6 7 5 3 1 1
55+
4 4 7 6 2 2 8 1 7
56+
9 6 8 5 7 3 7 9 5
57+
7 3 1 4 1 1 8 5 3
58+
4 6 8 9 4 5 3 8 8
59+
1 3 4 2 4 1 1 3 6
60+
5 9 2 3 5 2 4 8 5
61+
10 5 30
62+
7 4 7 5 9 3 6 4 6 7
63+
8 9 8 4 5 7 8 9 2 9
64+
6 5 3 4 6 4 7 6 3 2
65+
4 7 4 3 4 7 3 3 4 3
66+
3 5 6 4 8 8 2 1 8 6
67+
3 7 9 7 1 7 6 2 8 9
68+
3 6 1 6 8 9 7 7 5 1
69+
4 3 5 6 2 1 2 6 3 6
70+
3 4 9 2 1 5 9 9 6 3
71+
9 9 7 3 7 5 5 5 8 4
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#1 174
2+
#2 131
3+
#3 145
4+
#4 155
5+
#5 166
6+
#6 239
7+
#7 166
8+
#8 172
9+
#9 291
10+
#10 464

0 commit comments

Comments
 (0)