結果

問題 No.771 しおり
ユーザー nobuta05nobuta05
提出日時 2022-04-03 15:44:11
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 1,979 bytes
コンパイル時間 1,572 ms
コンパイル使用メモリ 143,564 KB
実行使用メモリ 56,752 KB
最終ジャッジ日時 2023-09-04 16:36:53
合計ジャッジ時間 7,285 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 291 ms
56,752 KB
testcase_01 AC 31 ms
9,248 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,388 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 150 ms
28,744 KB
testcase_26 AC 4 ms
4,380 KB
testcase_27 AC 31 ms
9,284 KB
testcase_28 AC 69 ms
17,524 KB
testcase_29 AC 32 ms
8,244 KB
testcase_30 AC 307 ms
55,776 KB
testcase_31 AC 323 ms
56,076 KB
testcase_32 AC 8 ms
4,380 KB
testcase_33 AC 324 ms
56,180 KB
testcase_34 AC 314 ms
55,720 KB
testcase_35 AC 8 ms
4,376 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 3 ms
4,384 KB
testcase_38 AC 8 ms
4,376 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 138 ms
30,708 KB
testcase_41 AC 311 ms
55,896 KB
testcase_42 AC 300 ms
56,048 KB
testcase_43 AC 32 ms
8,232 KB
testcase_44 AC 311 ms
54,500 KB
testcase_45 AC 287 ms
54,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.string, std.conv;
import std.algorithm, std.math;
import std.range;
import std.container.rbtree, std.container.dlist;
import std.container.binaryheap, std.container.array;
import std.typecons;

alias mstring = char[];
const long INF = 1L << 60L;
// const long mod = 1_000_000_000 + 7;
const long mod = 998_244_353L;

void chmin (T)(ref T x, T y) {
  x = min(x, y);
}

void chmax (T)(ref T x, T y) {
  x = max(x, y);
}

// 単一の数値を取得
// readln.chomp.to!int;
//  or
// int a;
// readf("%s\n", a);

// 複数の数値を取得(可変数個の場合推奨)
// readln.chomp.split.map!(to!long).array

// 複数の数値を取得(固定数個の場合、推奨)
// int a, b;
// readf("%s %s\n", &a, &b);

// インデントを一個ずらして複数の数値を取得(累積和とかで1-indexedの方が良い時がある)
// long[] vs = readln.chomp.split.map!(to!long).array;
// vs = [0L] ~ vs;

// 小数点は以下で指定
// double ret = 10.0;
// writefln("%.12f", ret);

// 配列の最後の要素は arr[$-1] でアクセスできる

void main () {
  int N = readln.chomp.to!int;

  auto ab = new Tuple!(long, long)[](N);
  foreach (i; 0 .. N)
    readf ("%s %s\n", &(ab[i][0]), &(ab[i][1]));

  auto cst = new long[][](N, N);
  foreach (i; 0 .. N) {
    long ai = ab[i][0];
    long bi = ab[i][1];

    foreach (j; 0 .. N) {
      long aj = ab[j][0];
      long bj = ab[j][1];

      cst[i][j] = (bi - ai) + aj;
    }
  }

  auto dp = new long[][](1 << N, N);
  foreach (s; 0 .. (1 << N))
    foreach (i; 0 .. N)
      dp[s][i] = INF;
  foreach (i; 0 .. N)
    dp[1 << i][i] = 0L;

  foreach (s; 1 .. (1 << N))
    foreach (i; 0 .. N) {
      if ((s & (1 << i)) == 0)
        continue;

      foreach (j; 0 .. N) {
        if (s & (1 << j))
          continue;

        chmin(dp[s | (1 << j)][j], max(dp[s][i], cst[i][j]));
      }
    }

  long ret = INF;
  foreach (i; 0 .. N)
    chmin (ret, dp[(1 << N) - 1][i]);
  writeln(ret);
}
0