結果

問題 No.771 しおり
ユーザー nanaenanae
提出日時 2018-12-31 19:38:18
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 316 ms / 2,000 ms
コード長 1,588 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 93,432 KB
実行使用メモリ 34,804 KB
最終ジャッジ日時 2023-09-03 21:47:28
合計ジャッジ時間 7,089 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 265 ms
34,496 KB
testcase_01 AC 31 ms
5,444 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 142 ms
19,548 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 32 ms
5,468 KB
testcase_28 AC 68 ms
11,652 KB
testcase_29 AC 33 ms
7,204 KB
testcase_30 AC 298 ms
34,720 KB
testcase_31 AC 312 ms
34,348 KB
testcase_32 AC 8 ms
4,376 KB
testcase_33 AC 316 ms
34,804 KB
testcase_34 AC 291 ms
34,028 KB
testcase_35 AC 7 ms
4,376 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 8 ms
5,120 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 135 ms
19,316 KB
testcase_41 AC 300 ms
33,508 KB
testcase_42 AC 303 ms
34,548 KB
testcase_43 AC 33 ms
5,396 KB
testcase_44 AC 305 ms
33,752 KB
testcase_45 AC 274 ms
34,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

enum inf = 1<<30;

void main() {
    int n;
    scan(n);

    auto a = new int[](n);
    auto b = new int[](n);

    foreach (i ; 0 .. n) {
        scan(a[i], b[i]);
    }

    auto dp = new int[][](1<<n, n);
    //fillAll(dp, inf);

    foreach (s ; 0 .. 1<<n) {
        foreach (i ; 0 .. n) {
            if (!(s & (1<<i))) {
                continue;
            }

            int ss = s ^ (1<<i);

            if (!ss) {
                continue;
            }

            dp[s][i] = inf;

            foreach (j ; 0 .. n) {
                if (!(ss & (1<<j))) {
                    continue;
                }
                auto t = max(dp[ss][j], a[i] + b[j] - a[j]);
                dp[s][i] = min(dp[s][i], t);
            }
        }
    }

    int ans = inf;

    foreach (i ; 0 .. n) {
        ans = min(ans, dp[(1<<n) - 1][i]);
    }

    writeln(ans);
}






























void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
0