結果

問題 No.929 よくあるボールを移動するやつ
ユーザー Konton7Konton7
提出日時 2019-11-22 22:17:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 728 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 83,840 KB
最終ジャッジ日時 2024-04-19 11:45:52
合計ジャッジ時間 1,577 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
54,016 KB
testcase_01 AC 38 ms
53,888 KB
testcase_02 AC 38 ms
53,504 KB
testcase_03 AC 37 ms
53,760 KB
testcase_04 AC 35 ms
53,504 KB
testcase_05 AC 37 ms
53,504 KB
testcase_06 AC 39 ms
53,760 KB
testcase_07 AC 56 ms
72,320 KB
testcase_08 AC 75 ms
83,456 KB
testcase_09 AC 77 ms
83,712 KB
testcase_10 AC 73 ms
83,840 KB
testcase_11 AC 65 ms
80,896 KB
testcase_12 AC 64 ms
78,336 KB
testcase_13 AC 59 ms
75,904 KB
testcase_14 AC 60 ms
77,184 KB
testcase_15 AC 65 ms
79,360 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