結果

問題 No.771 しおり
コンテスト
ユーザー k
提出日時 2020-09-14 01:10:26
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 655 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,197 ms
コンパイル使用メモリ 212,416 KB
実行使用メモリ 21,888 KB
最終ジャッジ日時 2026-06-13 18:35:58
合計ジャッジ時間 4,397 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

const int INF = 1e6;
int dp[1<<18][18];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  vector<int> a(n), b(n);
  REP (i, n) cin >> a[i] >> b[i];

  REP (i, 1<<n) REP (j, n) dp[i][j] = INF;
  
  REP (i, n) dp[1<<i][i] = 0;
  REP (i, 1<<n) REP (j, n) {
    if (dp[i][j] == INF) continue;
    REP (k, n) {
      if (i & 1<<k) continue;
      dp[i|1<<k][k] = min(dp[i|1<<k][k], max(dp[i][j], b[j]-a[j]+a[k]));
    }
  }
  
  int ret = INF;
  REP (i, n) ret = min(ret, dp[(1<<n)-1][i]);
  cout << ret << endl;
  
  return 0;
}
0