結果

問題 No.771 しおり
ユーザー tottoripapertottoripaper
提出日時 2018-12-19 21:28:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 305 ms / 2,000 ms
コード長 1,087 bytes
コンパイル時間 1,470 ms
コンパイル使用メモリ 165,508 KB
実行使用メモリ 22,052 KB
最終ジャッジ日時 2023-09-29 12:48:45
合計ジャッジ時間 6,583 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 288 ms
21,828 KB
testcase_01 AC 29 ms
21,788 KB
testcase_02 AC 6 ms
21,828 KB
testcase_03 AC 7 ms
21,968 KB
testcase_04 AC 6 ms
21,752 KB
testcase_05 AC 6 ms
21,828 KB
testcase_06 AC 6 ms
21,808 KB
testcase_07 AC 7 ms
21,804 KB
testcase_08 AC 7 ms
21,824 KB
testcase_09 AC 6 ms
21,876 KB
testcase_10 AC 6 ms
21,768 KB
testcase_11 AC 6 ms
21,764 KB
testcase_12 AC 6 ms
21,808 KB
testcase_13 AC 6 ms
21,752 KB
testcase_14 AC 7 ms
21,824 KB
testcase_15 AC 6 ms
21,752 KB
testcase_16 AC 6 ms
21,836 KB
testcase_17 AC 6 ms
21,756 KB
testcase_18 AC 7 ms
21,820 KB
testcase_19 AC 7 ms
21,780 KB
testcase_20 AC 7 ms
21,780 KB
testcase_21 AC 7 ms
21,868 KB
testcase_22 AC 6 ms
21,808 KB
testcase_23 AC 6 ms
21,768 KB
testcase_24 AC 7 ms
21,772 KB
testcase_25 AC 123 ms
21,816 KB
testcase_26 AC 8 ms
21,940 KB
testcase_27 AC 29 ms
21,968 KB
testcase_28 AC 58 ms
21,828 KB
testcase_29 AC 29 ms
21,836 KB
testcase_30 AC 291 ms
22,052 KB
testcase_31 AC 303 ms
21,904 KB
testcase_32 AC 11 ms
21,748 KB
testcase_33 AC 296 ms
21,788 KB
testcase_34 AC 294 ms
21,816 KB
testcase_35 AC 11 ms
21,940 KB
testcase_36 AC 7 ms
21,752 KB
testcase_37 AC 8 ms
22,008 KB
testcase_38 AC 11 ms
21,828 KB
testcase_39 AC 7 ms
21,748 KB
testcase_40 AC 124 ms
21,820 KB
testcase_41 AC 292 ms
21,968 KB
testcase_42 AC 290 ms
21,768 KB
testcase_43 AC 29 ms
21,756 KB
testcase_44 AC 305 ms
21,792 KB
testcase_45 AC 289 ms
21,756 KB
権限があれば一括ダウンロードができます

ソースコード

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