結果

問題 No.771 しおり
ユーザー iqueue02
提出日時 2019-11-21 22:04:03
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 771 bytes
コンパイル時間 1,773 ms
コンパイル使用メモリ 171,568 KB
実行使用メモリ 22,912 KB
最終ジャッジ日時 2024-07-22 07:18:59
合計ジャッジ時間 4,583 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
const int INF = 1e9;
int main(){
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i,n) cin >> a[i] >> b[i];
  vector<vector<int> > dp(n,vector<int>(1<<n,INF));
  for (int i = 0; i < n; i++) dp[i][(1<<i)] = 0;
  int res = INF;
  for (int bit = 0 ; bit < (1<<n); bit++) {
    for (int i = 0; i < n; i++) {
      if (bit&(1<<i)) continue;
      for (int j = 0; j < n; j++) {
        if (!(bit&(1<<j))) continue;
        dp[i][bit | (1 << i)] = min(dp[i][bit | (1<<i)], max(dp[j][bit], b[i] - a[i] + a[j]));
      }
    }
  }
  rep(i,n) res = min(res,dp[i][(1<<n)-1]);
  cout << res << endl;
  return 0;
}
0