結果

問題 No.771 しおり
ユーザー veqccveqcc
提出日時 2019-02-16 13:37:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 295 ms / 2,000 ms
コード長 1,081 bytes
コンパイル時間 715 ms
コンパイル使用メモリ 90,592 KB
実行使用メモリ 24,056 KB
最終ジャッジ日時 2023-09-29 12:53:23
合計ジャッジ時間 5,521 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 281 ms
23,764 KB
testcase_01 AC 28 ms
5,860 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 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 3 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 130 ms
13,576 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 30 ms
5,952 KB
testcase_28 AC 63 ms
8,656 KB
testcase_29 AC 29 ms
5,932 KB
testcase_30 AC 277 ms
23,852 KB
testcase_31 AC 286 ms
23,772 KB
testcase_32 AC 7 ms
4,380 KB
testcase_33 AC 277 ms
23,756 KB
testcase_34 AC 275 ms
23,880 KB
testcase_35 AC 8 ms
4,376 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 7 ms
4,380 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 124 ms
13,584 KB
testcase_41 AC 276 ms
23,748 KB
testcase_42 AC 264 ms
24,056 KB
testcase_43 AC 30 ms
5,836 KB
testcase_44 AC 268 ms
23,780 KB
testcase_45 AC 295 ms
23,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int n;
int a[20], b[20], dp[1 << 20][20];

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    // dp[i][j] : i -> どれを使ったか、j -> 直前に何を使ったか
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                if (!(i & (1 << j))) continue;
                if (i & (1 << k)) continue;

                int l = i | (1 << k);
                int mx = max(dp[i][j], b[j] - a[j] + a[k]);
                dp[l][k] = dp[l][k] ? min(dp[l][k], mx) : mx;
            }
        }
    }

    int mn = 2000;
    for (int i = 0; i < n; i++) {
        mn = min(mn, dp[(1 << n) - 1][i]);
    }

    cout << mn << "\n";
    return 0;
}
0