結果

問題 No.1650 Moving Coins
ユーザー nebukuro09nebukuro09
提出日時 2021-08-20 21:48:38
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 985 bytes
コンパイル時間 1,045 ms
コンパイル使用メモリ 107,892 KB
実行使用メモリ 51,752 KB
最終ジャッジ日時 2023-09-04 13:40:58
合計ジャッジ時間 10,211 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 56 ms
4,380 KB
testcase_04 AC 43 ms
4,384 KB
testcase_05 AC 53 ms
4,380 KB
testcase_06 AC 58 ms
4,380 KB
testcase_07 AC 59 ms
4,384 KB
testcase_08 AC 92 ms
11,176 KB
testcase_09 AC 106 ms
25,756 KB
testcase_10 AC 96 ms
10,564 KB
testcase_11 AC 103 ms
17,824 KB
testcase_12 AC 84 ms
10,768 KB
testcase_13 AC 86 ms
11,044 KB
testcase_14 AC 99 ms
15,676 KB
testcase_15 AC 79 ms
9,120 KB
testcase_16 AC 106 ms
16,548 KB
testcase_17 AC 102 ms
15,904 KB
testcase_18 AC 111 ms
16,884 KB
testcase_19 AC 152 ms
51,752 KB
testcase_20 AC 124 ms
20,932 KB
testcase_21 AC 141 ms
35,700 KB
testcase_22 AC 125 ms
21,212 KB
testcase_23 AC 124 ms
21,612 KB
testcase_24 AC 58 ms
4,384 KB
testcase_25 AC 58 ms
4,380 KB
testcase_26 AC 64 ms
20,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto B = readln.split.map!(to!int).array;

    int ans = N.iota.map!(i => abs(A[i] - B[i])).sum;
    ans.writeln;

    void dfs(int i) {
        if (i == N) return;
        if (A[i] >= B[i]) {
            foreach (_; 0..A[i] - B[i]) writeln(i+1, " L");
            dfs(i + 1);
        } else {
            while (i != N - 1 && A[i] < B[i] && A[i] + 1 < A[i + 1]) {
                A[i] += 1;
                writeln(i + 1, " R");
            }
            if (A[i] == B[i]) dfs(i + 1);
            else {
                dfs(i + 1);
                while (A[i] < B[i]) {
                    writeln(i + 1, " R");
                    A[i] += 1;
                }
            }
        }
    }

    dfs(0);
}
0