結果
| 問題 |
No.929 よくあるボールを移動するやつ
|
| コンテスト | |
| ユーザー |
Konton7
|
| 提出日時 | 2019-11-22 22:17:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 89 ms / 2,000 ms |
| コード長 | 728 bytes |
| コンパイル時間 | 164 ms |
| コンパイル使用メモリ | 82,376 KB |
| 実行使用メモリ | 83,456 KB |
| 最終ジャッジ日時 | 2024-10-11 03:58:13 |
| 合計ジャッジ時間 | 1,786 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 12 |
ソースコード
import collections
n = int(input())
num = [ int(v) for v in input().split() ]
moveleft_que, moveright_que = collections.deque([]), collections.deque([])
l, r = 0, 0
ans = 0
for i, v in enumerate(num):
if v != 1:
if v == 0:
if l == 0:
moveright_que.append(i)
r += 1
else:
p = moveleft_que.popleft()
l -= 1
ans += abs(i-p)
else:
for _ in range(v-1):
if r == 0:
moveleft_que.append(i)
l += 1
else:
p = moveright_que.popleft()
r -= 1
ans += abs(i-p)
print(ans)
Konton7