結果

問題 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  
実行時間 594 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 576 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 65,836 KB
最終ジャッジ日時 2023-08-04 06:15:23
合計ジャッジ時間 10,136 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,800 KB
testcase_01 AC 16 ms
7,780 KB
testcase_02 AC 16 ms
7,784 KB
testcase_03 AC 24 ms
11,596 KB
testcase_04 AC 22 ms
10,348 KB
testcase_05 AC 22 ms
11,160 KB
testcase_06 AC 24 ms
11,620 KB
testcase_07 AC 24 ms
11,556 KB
testcase_08 AC 249 ms
36,232 KB
testcase_09 AC 227 ms
37,280 KB
testcase_10 AC 255 ms
38,340 KB
testcase_11 AC 254 ms
38,456 KB
testcase_12 AC 153 ms
28,564 KB
testcase_13 AC 159 ms
28,872 KB
testcase_14 AC 229 ms
36,608 KB
testcase_15 AC 137 ms
24,924 KB
testcase_16 AC 289 ms
39,828 KB
testcase_17 AC 290 ms
39,668 KB
testcase_18 AC 308 ms
42,340 KB
testcase_19 AC 466 ms
65,836 KB
testcase_20 AC 478 ms
64,648 KB
testcase_21 AC 468 ms
64,436 KB
testcase_22 AC 583 ms
62,752 KB
testcase_23 AC 594 ms
62,888 KB
testcase_24 AC 24 ms
11,012 KB
testcase_25 AC 24 ms
11,028 KB
testcase_26 AC 183 ms
39,084 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