結果

問題 No.1650 Moving Coins
ユーザー shotoyooshotoyoo
提出日時 2021-08-20 23:17:21
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 1,086 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 130,252 KB
最終ジャッジ日時 2023-08-04 09:57:08
合計ジャッジ時間 9,548 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,488 KB
testcase_01 AC 72 ms
71,332 KB
testcase_02 AC 74 ms
71,492 KB
testcase_03 AC 138 ms
92,244 KB
testcase_04 AC 109 ms
87,676 KB
testcase_05 AC 119 ms
89,472 KB
testcase_06 AC 124 ms
91,132 KB
testcase_07 AC 122 ms
92,224 KB
testcase_08 AC 170 ms
104,600 KB
testcase_09 AC 181 ms
106,472 KB
testcase_10 AC 173 ms
108,908 KB
testcase_11 AC 185 ms
108,608 KB
testcase_12 AC 164 ms
98,720 KB
testcase_13 AC 162 ms
100,160 KB
testcase_14 AC 173 ms
103,156 KB
testcase_15 AC 159 ms
98,904 KB
testcase_16 AC 192 ms
109,620 KB
testcase_17 AC 190 ms
110,652 KB
testcase_18 AC 201 ms
109,924 KB
testcase_19 AC 176 ms
115,220 KB
testcase_20 AC 183 ms
115,072 KB
testcase_21 AC 186 ms
114,556 KB
testcase_22 AC 208 ms
130,220 KB
testcase_23 AC 210 ms
130,252 KB
testcase_24 AC 111 ms
90,796 KB
testcase_25 AC 117 ms
90,396 KB
testcase_26 AC 143 ms
111,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))

def runlength(s):
    if not s:
        return []
    c = s[0]
    v = 1
    n = len(s)
    l = []
    for i in range(1, n):
        if c==s[i]:
            v += 1
        else:
            l.append((c,v))
            c = s[i]
            v = 1
    l.append((c,v))
    return l

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
lr = [0]*n
for i in range(n):
    if a[i]<b[i]:
        lr[i] = 1
    elif a[i]>b[i]:
        lr[i] = -1
ans = []
res = runlength(lr)
i = 0
for c,v in res:
    if c==0:
        pass
    elif c==-1:
        for j in range(i, i+v):
            for _ in range(abs(a[j]-b[j])):
                ans.append(f"{j+1} L")
    else:
        for j in range(i, i+v)[::-1]:
            for _ in range(abs(a[j]-b[j])):
                ans.append(f"{j+1} R")
    i += v
print(len(ans))
write("\n".join(ans))
0