Skip to content

Commit 4433ca4

Browse files
authored
Merge pull request #882 from AlgorithmWithGod/0224LJH
[20250913] BOJ / G2 / 컬러볼 / 이종환
2 parents acda8a0 + 41def70 commit 4433ca4

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

0224LJH/202509/13 BOJ 컬러볼.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
11+
static int ballCnt,sum;
12+
static int[] ans,numSum;
13+
static ArrayList<Ball>[] balls;
14+
15+
static class Ball {
16+
int color;
17+
int idx;
18+
19+
public Ball (int color, int idx){
20+
this.color = color;
21+
this.idx = idx;
22+
}
23+
24+
}
25+
26+
27+
public static void main(String[] args) throws NumberFormatException, IOException {
28+
init();
29+
process();
30+
print();
31+
}
32+
33+
@SuppressWarnings("unchecked")
34+
public static void init() throws NumberFormatException, IOException {
35+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
36+
37+
ballCnt = Integer.parseInt(br.readLine());
38+
ans = new int[ballCnt];
39+
numSum = new int[ballCnt+1]; // i번 색상 공의 크기 합
40+
balls = new ArrayList[2001];
41+
42+
for (int i = 0 ; i <= 2000; i++) balls[i] = new ArrayList<>();
43+
44+
for (int i = 0; i < ballCnt; i++) {
45+
StringTokenizer st = new StringTokenizer(br.readLine());
46+
int color = Integer.parseInt(st.nextToken());
47+
int size = Integer.parseInt(st.nextToken());
48+
Ball b = new Ball(color,i);
49+
50+
balls[size].add(b);
51+
}
52+
53+
54+
55+
}
56+
57+
public static void process() {
58+
for (int i = 1; i <= 2000; i++) {
59+
ArrayList<Ball> tempBalls = balls[i];
60+
61+
for (Ball b: tempBalls) {
62+
ans[b.idx] = sum - numSum[b.color];
63+
}
64+
65+
for (Ball b: tempBalls) {
66+
numSum[b.color] += i;
67+
}
68+
sum += tempBalls.size() * i;
69+
70+
71+
}
72+
73+
74+
for (int i = 0; i < ballCnt; i++) {
75+
sb.append(ans[i]).append("\n");
76+
}
77+
}
78+
79+
public static void print() {
80+
System.out.println(sb.toString());
81+
}
82+
}```

0 commit comments

Comments
 (0)