結果

問題 No.929 よくあるボールを移動するやつ
ユーザー Konton7Konton7
提出日時 2019-11-22 22:17:06
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 728 bytes
コンパイル時間 363 ms
コンパイル使用メモリ 86,680 KB
実行使用メモリ 84,972 KB
最終ジャッジ日時 2023-08-01 12:10:14
合計ジャッジ時間 3,061 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,436 KB
testcase_01 AC 90 ms
71,272 KB
testcase_02 AC 96 ms
71,756 KB
testcase_03 AC 93 ms
71,480 KB
testcase_04 AC 91 ms
71,408 KB
testcase_05 AC 90 ms
71,464 KB
testcase_06 AC 91 ms
71,464 KB
testcase_07 AC 117 ms
79,896 KB
testcase_08 AC 135 ms
84,972 KB
testcase_09 AC 133 ms
84,964 KB
testcase_10 AC 129 ms
84,620 KB
testcase_11 AC 124 ms
84,904 KB
testcase_12 AC 116 ms
84,684 KB
testcase_13 AC 117 ms
84,380 KB
testcase_14 AC 116 ms
84,740 KB
testcase_15 AC 121 ms
84,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0