結果

問題 No.693 square1001 and Permutation 2
ユーザー gew1fw
提出日時 2025-06-12 21:42:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 429 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 82,208 KB
実行使用メモリ 53,016 KB
最終ジャッジ日時 2025-06-12 21:46:23
合計ジャッジ時間 1,018 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))

count = [0] * (n + 1)
for num in a:
    count[num] += 1

excess = []
for i in range(1, n + 1):
    if count[i] > 1:
        excess.extend([i] * (count[i] - 1))

missing = []
for i in range(1, n + 1):
    if count[i] == 0:
        missing.append(i)

excess.sort()
missing.sort()

total_cost = 0
for x, y in zip(excess, missing):
    total_cost += abs(x - y)

print(total_cost)
0