Skip to content

Commit 989cf59

Browse files
committed
[Silver III] Title: 크로스 컨트리, Time: 168 ms, Memory: 16252 KB -BaekjoonHub
1 parent e0588cf commit 989cf59

File tree

2 files changed

+196
-0
lines changed

2 files changed

+196
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# [Silver III] 크로스 컨트리 - 9017
2+
3+
[문제 링크](https://www.acmicpc.net/problem/9017)
4+
5+
### 성능 요약
6+
7+
메모리: 16252 KB, 시간: 168 ms
8+
9+
### 분류
10+
11+
구현
12+
13+
### 제출 일자
14+
15+
2026년 2월 2일 22:02:08
16+
17+
### 문제 설명
18+
19+
<p>크로스 컨트리 달리기는 주자들이 자연적인 야외의 지형에 만들어진 코스를 달리는 운동 경기이다. 경주 코스는 일반적으로 4에서 12 킬로미터이며, 숲이나 넓은 땅을 통과하는 풀과 흙으로 된 지면과 언덕과 평평한 지형을 포함한다. 이 경기는 주자들의 개인성적을 매기고, 이를 가지고 팀의 점수를 계산한다. </p>
20+
21+
<p>한 팀은 여섯 명의 선수로 구성되며, 팀 점수는 상위 네 명의 주자의 점수를 합하여 계산한다. 점수는 자격을 갖춘 팀의 주자들에게만 주어지며, 결승점을 통과한 순서대로 점수를 받는다. 이 점수를 더하여 가장 낮은 점수를 얻는 팀이 우승을 하게 된다. 여섯 명의 주자가 참가하지 못한 팀은 점수 계산에서 제외된다. 동점의 경우에는 다섯 번째 주자가 가장 빨리 들어온 팀이 우승하게 된다.</p>
22+
23+
<p>예를 들어, 다음의 표를 살펴보자.</p>
24+
25+
<table class="table table-bordered" style="width:60%">
26+
<thead>
27+
<tr>
28+
<th>등수</th>
29+
<th>1</th>
30+
<th>2</th>
31+
<th>3</th>
32+
<th>4</th>
33+
<th>5</th>
34+
<th>6</th>
35+
<th>7</th>
36+
<th>8</th>
37+
<th>9</th>
38+
<th>10</th>
39+
<th>11</th>
40+
<th>12</th>
41+
<th>13</th>
42+
<th>14</th>
43+
<th>15</th>
44+
</tr>
45+
</thead>
46+
<tbody>
47+
<tr>
48+
<th>팀</th>
49+
<td>A</td>
50+
<td>B</td>
51+
<td>C</td>
52+
<td>C</td>
53+
<td>A</td>
54+
<td>C</td>
55+
<td>B</td>
56+
<td>D</td>
57+
<td>A</td>
58+
<td>A</td>
59+
<td>C</td>
60+
<td>A</td>
61+
<td>C</td>
62+
<td>C</td>
63+
<td>A</td>
64+
</tr>
65+
<tr>
66+
<th>점수</th>
67+
<td>1</td>
68+
<td>n/a</td>
69+
<td>2</td>
70+
<td>3</td>
71+
<td>4</td>
72+
<td>5</td>
73+
<td>n/a</td>
74+
<td>n/a</td>
75+
<td>6</td>
76+
<td>7</td>
77+
<td>8</td>
78+
<td>9</td>
79+
<td>10</td>
80+
<td>11</td>
81+
<td>12</td>
82+
</tr>
83+
</tbody>
84+
</table>
85+
86+
<p>팀 B 와 D 는 선수의 수가 여섯이 아니므로, 점수를 받을 수 없다. 팀 A 의 점수는 18 (1+4+6+7)이고, 팀 C 의 점수는 18 (2+3+5+8)이다. 이 경우 두 팀의 점수가 같으므로 다섯 번째로 결승점을 통과한 선수를 고려한다, A 팀의 다섯 번째 선수의 점수가 C 팀의 다섯 번째 선수의 점수보다 적으므로 A 팀이 우승팀이 된다.</p>
87+
88+
<p>모든 선수들의 등수가 주어질 때, 우승팀을 구하는 프로그램을 작성하라. 각 팀의 참가 선수가 여섯보다 작으면 그 팀은 점수 계산에서 제외됨을 주의하라. 여섯 명 보다 많은 선수가 참가하는 팀은 없고, 적어도 한 팀은 참가 선수가 여섯이며, 모든 선수는 끝까지 완주를 한다고 가정한다.</p>
89+
90+
### 입력
91+
92+
<p>입력 데이터는 표준입력을 사용한다. 입력은 T 개의 테스트 케이스로 주어진다. 입력 파일의 첫 번째 줄에 테스트 케이스의 수를 나타내는 정수 T 가 주어진다. 두 번째 줄부터는 두 줄에 하나의 테스트 케이스에 해당하는 데이터가 주어진다. 각 테스트 케이스의 첫 번째 줄에는 하나의 정수 N (6 ≤ N ≤ 1,000)이 주어진다. 두 번째 줄에는 팀 번호를 나타내는 N 개의 정수 t<sub>1</sub>, t<sub>2</sub>, …, t<sub>N</sub> 이 공백을 사이에 두고 주어진다. 각 팀은 1 과 M(1 ≤ M ≤ 200)사이의 정수로 표현된다.</p>
93+
94+
### 출력
95+
96+
<p>출력은 표준출력을 사용한다. 하나의 테스트 케이스에 대한 우승팀의 번호를 한 줄에 출력한다. </p>
97+
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
static int T, n;
7+
static int[] arr;
8+
static Map<Integer, Integer> teams;
9+
static Map<Integer, Team> gameInfo;
10+
static StringTokenizer st;
11+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
12+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
13+
14+
public static void main(String[] args) throws Exception {
15+
T = Integer.parseInt(br.readLine());
16+
17+
for (int t = 0; t < T; t++) {
18+
preSetting();
19+
teams = findCount();
20+
gameInfo = calTeamScore();
21+
22+
ArrayList<Map.Entry<Integer, Team>> list = new ArrayList<>(gameInfo.entrySet());
23+
24+
list.sort((e1, e2) ->{
25+
Team o1 = e1.getValue();
26+
Team o2 = e2.getValue();
27+
28+
if(o1.score == o2.score){
29+
return o1.fiveScore - o2.fiveScore;
30+
}
31+
return o1.score - o2.score;
32+
});
33+
34+
bw.append(String.valueOf(list.get(0).getKey())).append("\n");
35+
}
36+
bw.close();
37+
}
38+
39+
static Map<Integer, Team> calTeamScore(){
40+
Map<Integer, Team> answer = new HashMap<>();
41+
42+
int s = 0;
43+
int team;
44+
Team info;
45+
for(int i = 0; i < n ; i++){
46+
if(!teams.containsKey(arr[i])) continue;
47+
s++;
48+
49+
team = arr[i];
50+
if(answer.containsKey(team)){
51+
info = answer.get(team);
52+
53+
if(info.cnt < 4) info.score += s;
54+
info.cnt++;
55+
56+
if(info.cnt == 5) info.fiveScore = s;
57+
58+
answer.put(team, info);
59+
} else{
60+
answer.put(team, new Team(s));
61+
}
62+
}
63+
64+
return answer;
65+
}
66+
67+
static Map<Integer, Integer> findCount(){
68+
Map<Integer, Integer> answer = new HashMap<>();
69+
70+
int count;
71+
for(int i = 0; i < n ; i++){
72+
if(answer.containsKey(arr[i])){
73+
count = answer.get(arr[i]);
74+
75+
answer.put(arr[i], count + 1);
76+
} else answer.put(arr[i], 1);
77+
}
78+
79+
answer.values().removeIf(cnt -> cnt < 6);
80+
81+
return answer;
82+
}
83+
84+
static void preSetting() throws Exception{
85+
n = Integer.parseInt(br.readLine());
86+
arr = new int[n];
87+
88+
st = new StringTokenizer(br.readLine());
89+
for(int i = 0; i < n ; i++) arr[i] = Integer.parseInt(st.nextToken());
90+
}
91+
92+
static class Team {
93+
int fiveScore, score, cnt;
94+
Team(int score){
95+
this.score = score;
96+
this.cnt = 1;
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)