結果

問題 No.1650 Moving Coins
ユーザー c-yanc-yan
提出日時 2021-08-20 22:49:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 743 ms / 2,000 ms
コード長 996 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 49,488 KB
最終ジャッジ日時 2024-04-22 05:47:17
合計ジャッジ時間 14,305 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,880 KB
testcase_01 AC 32 ms
10,880 KB
testcase_02 AC 32 ms
11,008 KB
testcase_03 AC 195 ms
25,856 KB
testcase_04 AC 152 ms
22,144 KB
testcase_05 AC 179 ms
24,960 KB
testcase_06 AC 197 ms
26,240 KB
testcase_07 AC 200 ms
26,496 KB
testcase_08 AC 459 ms
39,528 KB
testcase_09 AC 462 ms
35,836 KB
testcase_10 AC 468 ms
40,412 KB
testcase_11 AC 474 ms
37,048 KB
testcase_12 AC 361 ms
32,564 KB
testcase_13 AC 374 ms
32,516 KB
testcase_14 AC 456 ms
36,192 KB
testcase_15 AC 333 ms
31,140 KB
testcase_16 AC 492 ms
38,640 KB
testcase_17 AC 486 ms
37,956 KB
testcase_18 AC 537 ms
40,720 KB
testcase_19 AC 727 ms
39,584 KB
testcase_20 AC 717 ms
49,488 KB
testcase_21 AC 717 ms
41,640 KB
testcase_22 AC 724 ms
49,468 KB
testcase_23 AC 743 ms
49,444 KB
testcase_24 AC 203 ms
26,624 KB
testcase_25 AC 200 ms
26,624 KB
testcase_26 AC 192 ms
38,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

def is_movable(n):
    if A[n] == B[n]:
        return False
    elif A[n] < B[n]:
        if n == N - 1:
            return True
        else:
            return B[n] < A[n + 1]
    elif A[n] > B[n]:
        if n == 0:
            return True
        else:
            return B[n] > A[n - 1]

q = deque([])
for i in range(N):
    if A[i] == B[i]:
        continue
    q.append(i)

result = []
while q:
    #print("*A", *A)
    i = q.popleft()
    #print(i)
    if not is_movable(i):
        continue
    #print(i, "is movable")
    if A[i] < B[i]:
        for j in range(B[i] - A[i]):
            result.append('%d R' % (i + 1))
    elif A[i] > B[i]:
        for j in range(A[i] - B[i]):
            result.append('%d L' % (i + 1))
    A[i] = B[i]
    if i != 0:
        q.append(i - 1)
    if i != N - 1:
        q.append(i + 1)
print(len(result))
print(*result, sep='\n')
0