結果

問題 No.693 square1001 and Permutation 2
ユーザー Pump0129
提出日時 2018-09-08 18:39:35
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 501 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-12-17 16:14:36
合計ジャッジ時間 1,178 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

if __name__ == "__main__":
    n = int(input())
    num_list = list(map(int, input().split(" ")))
    num_cnt_list = [0] * n
    for i in range(n):
        num_cnt_list[num_list[i] - 1] += 1
    j = 0
    ans = 0
    while j < n:
        if 1 < num_cnt_list[j]:
            zero_pos = num_cnt_list.index(0)
            num_cnt_list[j] -= 1
            num_cnt_list[zero_pos] += 1
            ans += abs(zero_pos - j)
            j = 0
        else:
            j += 1
    print(ans)
0