結果

問題 No.771 しおり
ユーザー tottoripaper
提出日時 2018-12-19 21:28:51
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 405 ms / 2,000 ms
コード長 1,087 bytes
コンパイル時間 1,769 ms
コンパイル使用メモリ 167,924 KB
実行使用メモリ 21,980 KB
最終ジャッジ日時 2024-07-22 07:07:33
合計ジャッジ時間 7,843 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

constexpr int INF = 1001001001;
int N;
int A[20], B[20];
int dp[1<<18][18];

int rec(int used, int p){
    if(used + 1 == (1 << N)){
        return 0;
    }

    if(dp[used][p] != -1){
        return dp[used][p];
    }

    int res = INF;
    for(int i=0;i<N;++i){
        if(used >> i & 1){
            continue;
        }

        int cost = used > 0 ? B[p] - A[p] + A[i] : 0;
        res = std::min(res, std::max(cost, rec(used | (1 << i), i)));
    }

    return dp[used][p] = res;
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> A[i] >> B[i];
    }

    memset(dp, -1, sizeof(dp));
    
    int res = rec(0, 0);
    std::cout << res << std::endl;
}
0