結果
| 問題 | No.3801 Split Pairs |
| コンテスト | |
| ユーザー |
kidodesu
|
| 提出日時 | 2026-11-13 23:44:08 |
| 言語 | PyPy3 (8.0.1 + ACL) |
| 結果 |
TLE
不安定
|
| 実行時間 | - |
| コード長 | 1,536 bytes |
| 記録 | |
| コンパイル時間 | 87 ms |
| コンパイル使用メモリ | 64,688 KB |
| 実行使用メモリ | 138,492 KB |
| 最終ジャッジ日時 | 2026-11-13 23:44:17 |
| 合計ジャッジ時間 | 8,126 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 13 TLE * 1 -- * 21 |
ソースコード
from collections import defaultdict as DD
def main():
n = int(input())
A = list(map(int, input().split()))
P = sorted(set(A))
ans = 0
D = DD(int)
for a in A:
D[a] += 1
pi = 1
now = P[0]
X = [[0, 1<<30]]
le = 0
while 1:
#print(now, X, ans, D[now])
cnt = D[now]
if X[-1][0] == 0:
X[-1][1] += 1
else:
X.append([0, 1])
for _ in range(cnt):
#print(X)
if X[-1][0] == 0:
X[-1][1] -= 1
if X[-1][1]:
X.append([1, 1])
else:
X.pop()
X[-1][1] += 1
else:
D[now+1] += 1
ans += X[-1][1]
cc = X.pop()[1]
X[-1][1] -= 1
if X[-1][1] == 0:
X.pop()
X[-1][1] += 1
X.append([0, 1])
else:
X.append([1, 1])
X.append([0, 1])
if cc-1:
X.append([1, cc-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
if X[-1][0] == 0:
X[-1][1] += nxt-now-1
else:
X.append([0, nxt-now-1])
now = nxt
return ans
print(main())
kidodesu