結果

問題 No.545 ママの大事な二人の子供
ユーザー kokatsukokatsu
提出日時 2023-01-11 00:13:59
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 871 bytes
コンパイル時間 2,045 ms
コンパイル使用メモリ 204,704 KB
実行使用メモリ 564,304 KB
最終ジャッジ日時 2023-09-04 19:36:39
合計ジャッジ時間 6,856 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,752 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 11 ms
6,332 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 MLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    long n;
    readf("%d\n", n);

    bool[long] L, R;
    L[0] = R[0] = true;
    foreach (i; 0 .. n) {
        long A, B;
        readf("%d %d\n", A, B);

        bool[long] nxt;
        if (i < n / 2) {
            foreach (l; L.byKey) {
                nxt[l+A] = nxt[l+B] = true;
                nxt[l-A] = nxt[l-B] = true;
            }
            L = nxt;
        }
        else {
            foreach (r; R.byKey) {
                nxt[r+A] = nxt[r+B] = true;
                nxt[r-A] = nxt[r-B] = true;
            }
            R = nxt;
        }
    }

    auto S = R.keys.sort;
    long res = long.max;
    foreach (l; L.byKey) {
        auto lb = S.lowerBound(l+1);
        if (!lb.empty) res = min(res, l-lb.back);

        auto ub = S.upperBound(l-1);
        if (!ub.empty) res = min(res, ub.front-l);
    }

    res.writeln;
}
0