結果

問題 No.1650 Moving Coins
ユーザー ygd.ygd.
提出日時 2021-08-20 22:43:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 413 ms / 2,000 ms
コード長 1,018 bytes
コンパイル時間 526 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 129,900 KB
最終ジャッジ日時 2023-08-04 07:47:19
合計ジャッジ時間 9,969 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,432 KB
testcase_01 AC 68 ms
71,636 KB
testcase_02 AC 68 ms
71,368 KB
testcase_03 AC 145 ms
78,744 KB
testcase_04 AC 139 ms
78,736 KB
testcase_05 AC 139 ms
77,952 KB
testcase_06 AC 148 ms
78,828 KB
testcase_07 AC 151 ms
78,672 KB
testcase_08 AC 215 ms
109,404 KB
testcase_09 AC 219 ms
105,584 KB
testcase_10 AC 211 ms
111,576 KB
testcase_11 AC 253 ms
111,392 KB
testcase_12 AC 200 ms
92,592 KB
testcase_13 AC 210 ms
93,172 KB
testcase_14 AC 232 ms
104,232 KB
testcase_15 AC 210 ms
90,988 KB
testcase_16 AC 263 ms
116,712 KB
testcase_17 AC 257 ms
118,460 KB
testcase_18 AC 278 ms
125,416 KB
testcase_19 AC 302 ms
129,900 KB
testcase_20 AC 413 ms
128,020 KB
testcase_21 AC 258 ms
126,884 KB
testcase_22 AC 250 ms
125,248 KB
testcase_23 AC 255 ms
125,264 KB
testcase_24 AC 128 ms
77,956 KB
testcase_25 AC 140 ms
78,080 KB
testcase_26 AC 173 ms
126,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def main():
    N = int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    A.sort()
    B.sort()
    Z = []
    M = 0
    for i in range(N):
        if B[i] - A[i] > 0:
            moji = "R"
        else:
            moji = "L"
        Z.append((abs(B[i] - A[i]), i, moji))
        M += abs(B[i] - A[i])
    print(M)
    #print(Z)
    stack = []
    for i in range(N):
        if Z[i][2] == "R":
            stack.append(Z[i])
            continue
        #ここで全部吐き出してよい
        while stack:
            move,idx,moji = stack.pop()
            for j in range(move):
                ret = [idx+1, "R"]
                print(*ret)
        #次を追加
        move,idx,moji = Z[i]
        for j in range(move):
            ret = [idx+1, "L"]
            print(*ret)
    while stack:
        move,idx,moji = stack.pop()
        for j in range(move):
            ret = [idx+1, "R"]
            print(*ret)

if __name__ == '__main__':
    main()
0