結果

問題 No.1767 BLUE to RED
ユーザー kokatsukokatsu
提出日時 2021-11-27 02:28:38
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 646 bytes
コンパイル時間 1,943 ms
コンパイル使用メモリ 204,360 KB
実行使用メモリ 21,828 KB
最終ジャッジ日時 2023-09-04 15:10:58
合計ジャッジ時間 5,386 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,504 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 80 ms
14,948 KB
testcase_10 AC 101 ms
15,788 KB
testcase_11 AC 87 ms
15,628 KB
testcase_12 AC 80 ms
15,540 KB
testcase_13 AC 109 ms
18,240 KB
testcase_14 AC 139 ms
21,828 KB
testcase_15 AC 139 ms
21,652 KB
testcase_16 AC 139 ms
21,572 KB
testcase_17 AC 140 ms
21,612 KB
testcase_18 AC 138 ms
21,608 KB
testcase_19 AC 140 ms
21,640 KB
testcase_20 AC 139 ms
21,644 KB
testcase_21 AC 139 ms
21,708 KB
testcase_22 AC 138 ms
21,524 KB
testcase_23 AC 141 ms
21,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    int N, M;
    readf("%d %d\n", N, M);

    auto A = readln.chomp.split.to!(long[]);
    auto B = readln.chomp.split.to!(long[]);

    A = [long.min / 2] ~ A ~ [long.max / 2];

    long res, pos;
    foreach (i; 0 .. N+1) {
        long[] C = [A[i]];
        while (pos < M && B[pos] < A[i+1]) {
            C ~= B[pos];
            ++pos;
        }

        auto l = C.length;
        if (l == 1) {
            continue;
        }

        C ~= A[i+1];

        long w;
        foreach (j; 0 .. l) {
            w = max(w, C[j+1]-C[j]);
        }
        
        res += A[i+1] - A[i] - w;
    }

    res.writeln;
}
0