結果

問題 No.771 しおり
ユーザー beetbeet
提出日時 2019-03-23 17:14:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 861 bytes
コンパイル時間 2,010 ms
コンパイル使用メモリ 201,576 KB
実行使用メモリ 40,256 KB
最終ジャッジ日時 2023-09-29 12:53:36
合計ジャッジ時間 6,318 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 211 ms
40,108 KB
testcase_01 AC 27 ms
32,316 KB
testcase_02 AC 3 ms
7,344 KB
testcase_03 AC 3 ms
7,348 KB
testcase_04 AC 3 ms
9,428 KB
testcase_05 AC 3 ms
11,448 KB
testcase_06 AC 2 ms
5,400 KB
testcase_07 AC 3 ms
9,460 KB
testcase_08 AC 5 ms
19,632 KB
testcase_09 AC 2 ms
5,344 KB
testcase_10 AC 2 ms
5,336 KB
testcase_11 AC 2 ms
5,320 KB
testcase_12 AC 3 ms
9,384 KB
testcase_13 AC 3 ms
11,448 KB
testcase_14 AC 5 ms
21,772 KB
testcase_15 AC 2 ms
7,352 KB
testcase_16 AC 4 ms
13,484 KB
testcase_17 AC 4 ms
17,808 KB
testcase_18 AC 3 ms
9,468 KB
testcase_19 AC 3 ms
13,508 KB
testcase_20 AC 2 ms
7,360 KB
testcase_21 AC 3 ms
9,384 KB
testcase_22 AC 4 ms
13,504 KB
testcase_23 AC 5 ms
15,584 KB
testcase_24 AC 5 ms
17,604 KB
testcase_25 AC 104 ms
37,036 KB
testcase_26 AC 8 ms
25,808 KB
testcase_27 AC 27 ms
32,396 KB
testcase_28 AC 53 ms
34,500 KB
testcase_29 AC 28 ms
32,184 KB
testcase_30 AC 222 ms
40,140 KB
testcase_31 AC 226 ms
40,124 KB
testcase_32 AC 11 ms
28,156 KB
testcase_33 AC 222 ms
40,188 KB
testcase_34 AC 218 ms
40,188 KB
testcase_35 AC 11 ms
27,908 KB
testcase_36 AC 7 ms
23,780 KB
testcase_37 AC 6 ms
23,760 KB
testcase_38 AC 11 ms
27,932 KB
testcase_39 AC 6 ms
23,752 KB
testcase_40 AC 97 ms
37,032 KB
testcase_41 AC 218 ms
40,256 KB
testcase_42 AC 208 ms
40,192 KB
testcase_43 AC 28 ms
32,204 KB
testcase_44 AC 209 ms
40,140 KB
testcase_45 AC 216 ms
40,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MAX = 18;
const Int INF = 1e5;
Int dp[MAX][1<<MAX];
signed main(){
  Int n;
  cin>>n;
  vector<Int> x(n),y(n);
  for(Int i=0;i<n;i++) cin>>x[i]>>y[i];
  
  Int s=1<<n;
  for(Int b=0;b<s;b++)
    for(Int i=0;i<n;i++)
      dp[i][b]=INF;
  
  for(Int i=0;i<n;i++) dp[i][1<<i]=0;

  for(Int b=0;b<s;b++){
    for(Int i=0;i<n;i++){
      if((~b>>i)&1) continue;
      for(Int j=0;j<n;j++){
        if((b>>j)&1) continue;
        chmin(dp[j][b|(1<<j)],max(dp[i][b],(y[i]-x[i])+x[j]));
      }
    }    
  }
  
  Int ans=dp[0][s-1];
  for(Int i=1;i<n;i++) chmin(ans,dp[i][s-1]);
  cout<<ans<<endl;
  return 0;
}
0