結果

問題 No.771 しおり
ユーザー tumuztumuz
提出日時 2023-10-20 15:23:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 1,491 bytes
コンパイル時間 2,243 ms
コンパイル使用メモリ 206,904 KB
実行使用メモリ 29,856 KB
最終ジャッジ日時 2023-10-20 15:23:26
合計ジャッジ時間 6,944 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 215 ms
29,856 KB
testcase_01 AC 24 ms
6,760 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 103 ms
16,528 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 24 ms
6,760 KB
testcase_28 AC 49 ms
9,928 KB
testcase_29 AC 24 ms
6,760 KB
testcase_30 AC 223 ms
29,856 KB
testcase_31 AC 220 ms
29,856 KB
testcase_32 AC 6 ms
4,348 KB
testcase_33 AC 220 ms
29,856 KB
testcase_34 AC 218 ms
29,856 KB
testcase_35 AC 7 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 3 ms
4,348 KB
testcase_38 AC 7 ms
4,348 KB
testcase_39 AC 3 ms
4,348 KB
testcase_40 AC 103 ms
16,528 KB
testcase_41 AC 226 ms
29,856 KB
testcase_42 AC 221 ms
29,856 KB
testcase_43 AC 24 ms
6,760 KB
testcase_44 AC 222 ms
29,856 KB
testcase_45 AC 220 ms
29,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep1(i,n) for(int i=1; i<=(n); i++)
#define sz(x) int(x.size())
#define all(x) (x).begin(),(x).end()
#define Q2 1000000007
#define Q 998244353
#define lINF LONG_LONG_MAX  //ll
#define iINF INT_MAX //int
#define yes "Yes"
#define no "No"
#define kotae cout<<ans<<endl;
#define dame { puts("0"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
using ll=long long;
using ull=unsigned long long;
using P=pair<int,int>;
using pqg=priority_queue<int,vector<int>,greater<int>>;
using vi=vector<int>;
using vi2=vector<vector<int>>;
using vi3=vector<vector<vector<int>>>;
using vl=vector<ll>;
using vl2=vector<vector<ll>>;
using vl3=vector<vector<vector<ll>>>;
using vs=vector<string>;
using vp=vector<P>;
using vp2=vector<vector<P>>;
void chmax(int &x, int y){ x=max(x,y); return; }
void chmin(int &x, int y){ x=min(x,y); return; }
void chmaxl(ll &x, ll y){ x=max(x,y); return; }
void chminl(ll &x, ll y){ x=min(x,y); return; }

int main() {  

  int n;
  cin >> n;
  vi a(n),b(n);
  rep(i,n) cin >> a[i] >> b[i];
  int s=1<<n;
  vi2 dp(s,vector<int>(n,iINF));
  rep(i,n) dp[1<<i][i]=0;
  
  rep(i,s){
    rep(j,n){
      if(!((i>>j)&1)) continue;
      rep(k,n){
        // from j to k
        if(j==k) continue;
        if((i>>k)&1) continue;
        chmin(dp[i+(1<<k)][k],max(dp[i][j],b[j]-a[j]+a[k]));
      }
    }
  }
  int ans=iINF;
  rep(i,n) chmin(ans,dp[s-1][i]);
  kotae;

  return 0;
}
0