結果

問題 No.771 しおり
ユーザー pionepione
提出日時 2020-06-13 19:16:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 275 ms / 2,000 ms
コード長 2,611 bytes
コンパイル時間 1,348 ms
コンパイル使用メモリ 170,860 KB
実行使用メモリ 46,500 KB
最終ジャッジ日時 2023-09-29 13:03:50
合計ジャッジ時間 5,810 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 269 ms
46,296 KB
testcase_01 AC 27 ms
9,424 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 123 ms
25,956 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 29 ms
9,452 KB
testcase_28 AC 56 ms
15,652 KB
testcase_29 AC 29 ms
9,540 KB
testcase_30 AC 267 ms
46,432 KB
testcase_31 AC 275 ms
46,376 KB
testcase_32 AC 8 ms
4,656 KB
testcase_33 AC 266 ms
46,360 KB
testcase_34 AC 259 ms
46,500 KB
testcase_35 AC 7 ms
4,664 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 7 ms
4,596 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 116 ms
26,020 KB
testcase_41 AC 265 ms
46,296 KB
testcase_42 AC 264 ms
46,368 KB
testcase_43 AC 30 ms
9,508 KB
testcase_44 AC 265 ms
46,380 KB
testcase_45 AC 254 ms
46,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[1001001][20]; // 集合sは既に並んでいて、最後がiであるときのしおり間距離の最大

ll bitcount(ll x){
  if(x==0) return 0;
  return bitcount(x>>1)+(x&1);
}

string to_binary(ll n, int digit = 0) {
  string res = "";
  while (n) {
    if (n & 1) res = "1" + res;
    else res = "0" + res;
    n >>= 1;
  }
  if (0 < digit) {
    int n = digit - res.length();
    rep(i, n) res = "0" + res;
  }
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  vpll p(n);
  rep(i,n){
    ll a,b; cin>>a>>b;
    p[i]={a,b};
  }
  
  rep(s,1<<n) rep(i,n) dp[s][i]=LINF;
  rep(i,n) dp[1<<i][i]=0;
  
  irep(s,1,1<<n){
    rep(i,n) rep(j,n){
      if(i==j) continue;
      if((s>>i&1)==0) continue;
      if((s>>j&1)) continue;
      
      ll d=(p[i].second-p[i].first)+p[j].first;
      chmin(dp[s|(1<<j)][j],max(dp[s][i],d));
      // cout<<to_binary(s,3)<<' '<<i<<' '<<j<<' '<<dp[s|(1<<j)][j]<<endl;
    }
  }
  
  ll ans=LINF;
  rep(i,n) chmin(ans,dp[(1<<n)-1][i]);
  
  cout<<ans<<endl;
  
}
0