結果

問題 No.693 square1001 and Permutation 2
ユーザー gew1fw
提出日時 2025-06-12 16:56:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 429 bytes
コンパイル時間 340 ms
コンパイル使用メモリ 82,056 KB
実行使用メモリ 52,224 KB
最終ジャッジ日時 2025-06-12 16:56:29
合計ジャッジ時間 1,320 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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