Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 780bccd

Browse files
[Silver II] Title: 좌표 압축, Time: 4788 ms, Memory: 281836 KB -BaekjoonHub
1 parent 066ea59 commit 780bccd

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# [Silver II] 좌표 압축 - 18870
2+
3+
[문제 링크](https://www.acmicpc.net/problem/18870)
4+
5+
### 성능 요약
6+
7+
메모리: 281836 KB, 시간: 4788 ms
8+
9+
### 분류
10+
11+
값 / 좌표 압축, 정렬
12+
13+
### 제출 일자
14+
15+
2024년 1월 26일 14:35:08
16+
17+
### 문제 설명
18+
19+
<p>수직선 위에 N개의 좌표 X<sub>1</sub>, X<sub>2</sub>, ..., X<sub>N</sub>이 있다. 이 좌표에 좌표 압축을 적용하려고 한다.</p>
20+
21+
<p>X<sub>i</sub>를 좌표 압축한 결과 X'<sub>i</sub>의 값은 X<sub>i</sub> > X<sub>j</sub>를 만족하는 서로 다른 좌표 X<sub>j</sub>의 개수와 같아야 한다.</p>
22+
23+
<p>X<sub>1</sub>, X<sub>2</sub>, ..., X<sub>N</sub>에 좌표 압축을 적용한 결과 X'<sub>1</sub>, X'<sub>2</sub>, ..., X'<sub>N</sub>를 출력해보자.</p>
24+
25+
### 입력
26+
27+
<p>첫째 줄에 N이 주어진다.</p>
28+
29+
<p>둘째 줄에는 공백 한 칸으로 구분된 X<sub>1</sub>, X<sub>2</sub>, ..., X<sub>N</sub>이 주어진다.</p>
30+
31+
### 출력
32+
33+
<p>첫째 줄에 X'<sub>1</sub>, X'<sub>2</sub>, ..., X'<sub>N</sub>을 공백 한 칸으로 구분해서 출력한다.</p>
34+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
import heapq
3+
from collections import defaultdict
4+
5+
input = sys.stdin.readline
6+
7+
n = int(input())
8+
nums = list(map(int,input().split()))
9+
answer = [0 for _ in range(n)]
10+
11+
count = defaultdict(list)
12+
for idx, num in enumerate(nums) :
13+
count[num].append(idx)
14+
15+
queue = []
16+
for key, values in count.items() :
17+
heapq.heappush(queue, (key, values))
18+
19+
total = 0
20+
while queue :
21+
_, idxs = heapq.heappop(queue)
22+
for idx in idxs :
23+
answer[idx] += total
24+
total += 1
25+
26+
print(*answer)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /