結果
| 問題 | No.3801 Split Pairs |
| コンテスト | |
| ユーザー |
kidodesu
|
| 提出日時 | 2026-11-13 23:58:31 |
| 言語 | PyPy3 (8.0.1 + ACL) |
| 結果 |
TLE
不安定
|
| 実行時間 | - |
| コード長 | 1,115 bytes |
| 記録 | |
| コンパイル時間 | 89 ms |
| コンパイル使用メモリ | 64,344 KB |
| 実行使用メモリ | 127,560 KB |
| 最終ジャッジ日時 | 2026-11-13 23:58:39 |
| 合計ジャッジ時間 | 7,879 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 13 TLE * 1 -- * 21 |
ソースコード
from collections import defaultdict as DD
from heapq import *
def main():
n = int(input())
A = list(map(int, input().split()))
P = sorted(set(A))
ans = 0
D = DD(int)
E = DD(int)
hq = []
for a in A:
D[a] += 1
pi = 1
now = P[0]
X = [[0, 1<<30]]
le = 0
while 1:
cnt = D[now]
#print(now, ans)
for _ in range(cnt):
if E[now] == 0:
E[now] = 1
if not E[now-1]:
heappush(hq, -now)
else:
D[now+1] += 1
nxt = -heappop(hq)
ans += now-nxt+1
E[nxt] = 0
E[nxt-1] = 1
if not E[nxt-2]:
heappush(hq, -(nxt-1))
if E[nxt+1]:
heappush(hq, -nxt-1)
if D[now+1] != 0:
now += 1
if pi < len(P) and P[pi] == now:
pi += 1
else:
if pi == len(P):
break
nxt = P[pi]
pi += 1
now = nxt
return ans
print(main())
kidodesu