結果

問題 No.1650 Moving Coins
ユーザー tktk_snsntktk_snsn
提出日時 2021-08-20 21:52:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 599 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 67,000 KB
最終ジャッジ日時 2024-04-22 04:21:34
合計ジャッジ時間 9,984 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 38 ms
14,208 KB
testcase_04 AC 36 ms
13,028 KB
testcase_05 AC 37 ms
13,824 KB
testcase_06 AC 39 ms
14,208 KB
testcase_07 AC 39 ms
14,208 KB
testcase_08 AC 273 ms
37,732 KB
testcase_09 AC 255 ms
38,088 KB
testcase_10 AC 282 ms
39,736 KB
testcase_11 AC 282 ms
39,044 KB
testcase_12 AC 176 ms
29,968 KB
testcase_13 AC 182 ms
29,932 KB
testcase_14 AC 252 ms
37,104 KB
testcase_15 AC 154 ms
27,040 KB
testcase_16 AC 317 ms
42,052 KB
testcase_17 AC 318 ms
41,024 KB
testcase_18 AC 338 ms
44,008 KB
testcase_19 AC 507 ms
67,000 KB
testcase_20 AC 513 ms
65,680 KB
testcase_21 AC 503 ms
65,572 KB
testcase_22 AC 599 ms
65,584 KB
testcase_23 AC 599 ms
65,572 KB
testcase_24 AC 38 ms
14,080 KB
testcase_25 AC 39 ms
13,940 KB
testcase_26 AC 204 ms
40,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

U = 10 ** 7
N = int(input())
A = [-1] + list(map(int, input().split())) + [U]
B = [-1] + list(map(int, input().split())) + [U]


answer = []
i = 0
while i <= N:
    while i <= N and A[i] == B[i]:
        i += 1

    # 左寄せ
    while i <= N and A[i] > B[i]:
        answer.append((i, B[i] - A[i]))
        i += 1

    while i <= N and A[i] == B[i]:
        i += 1

    # 右寄せ
    tmp = []
    while i <= N and A[i] < B[i]:
        tmp.append((i, B[i] - A[i]))
        i += 1
    answer.extend(tmp[::-1])

ans = []
cnt = 0
for i, d in answer:
    if d > 0:
        direction = "R"
    else:
        d = -d
        direction = "L"
    cnt += d
    ans.extend(
        ["{} {}".format(i, direction)] * d
    )

print(len(ans))
print("\n".join(ans))
0