結果
| 問題 |
No.2304 Distinct Elements
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-16 15:23:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 510 bytes |
| コンパイル時間 | 162 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 238,084 KB |
| 最終ジャッジ日時 | 2024-09-30 04:02:37 |
| 合計ジャッジ時間 | 11,377 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 45 WA * 13 |
ソースコード
n = int(input())
A = list(map(int, input().split()))
A.sort()
ans = [0] * n
cnt = {}
tot = 0
for i, a in enumerate(A):
x = a - i
cnt[x] = cnt.get(x, 0) + 1
tot += cnt.get(x + 1, 0)
cnt[x] += cnt.get(x + 1, 0)
cnt[x + 1] = 0
ans[i] += tot
A = [-a for a in A[::-1]]
ans = ans[::-1]
cnt = {}
tot = 0
for i, a in enumerate(A):
x = a - i
cnt[x] = cnt.get(x, 0) + 1
tot += cnt.get(x + 1, 0)
cnt[x] += cnt.get(x + 1, 0)
cnt[x + 1] = 0
ans[i] += tot
print(min(ans))