結果

問題 No.798 コレクション
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-03-19 17:24:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,304 bytes
コンパイル時間 2,638 ms
コンパイル使用メモリ 77,024 KB
実行使用メモリ 814,364 KB
最終ジャッジ日時 2023-10-12 01:06:10
合計ジャッジ時間 4,418 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,356 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 RE -
testcase_14 MLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<climits>

typedef long long ll;

int main(int argc, char const *argv[]) {
    ll n;
    std::cin >> n;
    std::vector<ll> a(n), b(n);
    for (ll i = 0; i < n; i++) std::cin >> a[i] >> b[i];

    std::vector<std::vector<ll>> dp(n + 1, std::vector<ll>(1 << n, LLONG_MAX));
    dp[0][0] = 0;
    for (ll x = 0; x < n; x++) {
        for (ll y = 0; y < (1 << n); y++) {
            if (dp[x][y] == LLONG_MAX) continue;

            for (ll z = 0; z < n; z++) {
                if ((y & (1 << z)) != 0) continue;
                dp[x + 1][y | (1 << z)] = std::min(dp[x + 1][y | (1 << z)], dp[x][y] + a[z] + b[z] * x);
            }

            if (x % 2 != 0) {
                for (ll s = 0; s < n; s++) {
                    for (ll t = s + 1; t < n; t++) {
                        if ((y & (1 << s)) != 0 || (y & (1 << t)) != 0) continue;
                        ll u = std::min(a[s] + b[s] * x, a[t] + b[t] * x);
                        dp[x + 1][y | (1 << s) | (1 << t)] = std::min(dp[x + 1][y | (1 << s) | (1 << t)], dp[x][y] + u);
                    }
                }
            }
        }
    }

    ll ans = LLONG_MAX;
    for (ll i = 0; i <= n; i++) {
        ans = std::min(ans, dp[i][(1 << n) - 1]);
    }

    std::cout << ans << std::endl;
}
0