結果
| 問題 | No.771 しおり | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-12-31 19:38:18 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 318 ms / 2,000 ms | 
| コード長 | 1,588 bytes | 
| コンパイル時間 | 630 ms | 
| コンパイル使用メモリ | 105,092 KB | 
| 実行使用メモリ | 32,256 KB | 
| 最終ジャッジ日時 | 2024-06-13 02:26:38 | 
| 合計ジャッジ時間 | 5,288 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 43 | 
ソースコード
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);
        }
    }
}
            
            
            
        