Submission #64282206
Source Code Expand
Copy
def compute_ranks(N, P):# (得点, インデックス) のペアを作成してソート(降順)sorted_scores = sorted(enumerate(P), key=lambda x: -x[1])ranks = [0] * N # 順位を格納するリストr = 1 # 初期順位i = 0 # 走査インデックスwhile i < N:score = sorted_scores[i][1] # 現在の最大得点count = 0 # 同じ得点の人数while i + count < N and sorted_scores[i + count][1] == score:count += 1for j in range(count):ranks[sorted_scores[i + j][0]] = rr += counti += countreturn ranks
def compute_ranks(N, P):
# (得点, インデックス) のペアを作成してソート(降順)
sorted_scores = sorted(enumerate(P), key=lambda x: -x[1])
ranks = [0] * N # 順位を格納するリスト
r = 1 # 初期順位
i = 0 # 走査インデックス
while i < N:
score = sorted_scores[i][1] # 現在の最大得点
count = 0 # 同じ得点の人数
while i + count < N and sorted_scores[i + count][1] == score:
count += 1
for j in range(count):
ranks[sorted_scores[i + j][0]] = r
r += count
i += count
return ranks
N = int(input())
P = list(map(int, input().split()))
result = compute_ranks(N, P)
print(*result)
Submission Info
| Submission Time | |
|---|---|
| Task | B - Ranking with Ties |
| User | juten |
| Language | Python (PyPy 3.10-v7.3.12) |
| Score | 200 |
| Code Size | 792 Byte |
| Status | AC |
| Exec Time | 55 ms |
| Memory | 76748 KB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 200 / 200 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 03_sorted_00.txt, 03_sorted_01.txt, 04_handmade_00.txt, 04_handmade_01.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 54 ms | 76568 KB |
| 00_sample_01.txt | AC | 54 ms | 76488 KB |
| 00_sample_02.txt | AC | 55 ms | 76340 KB |
| 00_sample_03.txt | AC | 54 ms | 76516 KB |
| 01_random_00.txt | AC | 54 ms | 76272 KB |
| 01_random_01.txt | AC | 54 ms | 76368 KB |
| 01_random_02.txt | AC | 54 ms | 76604 KB |
| 01_random_03.txt | AC | 54 ms | 76440 KB |
| 02_random2_00.txt | AC | 55 ms | 76352 KB |
| 02_random2_01.txt | AC | 54 ms | 76652 KB |
| 02_random2_02.txt | AC | 55 ms | 76616 KB |
| 02_random2_03.txt | AC | 55 ms | 76400 KB |
| 02_random2_04.txt | AC | 54 ms | 76616 KB |
| 02_random2_05.txt | AC | 55 ms | 76232 KB |
| 02_random2_06.txt | AC | 54 ms | 76480 KB |
| 02_random2_07.txt | AC | 54 ms | 76664 KB |
| 02_random2_08.txt | AC | 55 ms | 76632 KB |
| 03_sorted_00.txt | AC | 55 ms | 76508 KB |
| 03_sorted_01.txt | AC | 54 ms | 76656 KB |
| 04_handmade_00.txt | AC | 54 ms | 76656 KB |
| 04_handmade_01.txt | AC | 54 ms | 76748 KB |