0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AtCoder Beginner Contest: D問題解答集 Python

Posted at

AtCoder Beginner Contest 171

collections.defauldict(int) を使って、各数字の個数を数え上げておく

import collections
 
N = int(input())
A = sorted(map(int, input().split()))
 
cnt = collections.defaultdict(int)
for a in A:
    cnt[a] += 1
ans = sum(A)
 
Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    ans += (C - B) * cnt[B]
    cnt[C] += cnt[B]
    cnt[B] = 0

以降追加予定

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?