結果

問題 No.845 最長の切符
ユーザー merom686merom686
提出日時 2019-06-28 23:09:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 3,000 ms
コード長 1,117 bytes
コンパイル時間 617 ms
コンパイル使用メモリ 73,932 KB
実行使用メモリ 7,648 KB
最終ジャッジ日時 2023-09-14 22:36:35
合計ジャッジ時間 2,040 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 19 ms
7,508 KB
testcase_17 AC 6 ms
4,384 KB
testcase_18 AC 11 ms
5,392 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 19 ms
7,500 KB
testcase_21 AC 18 ms
7,440 KB
testcase_22 AC 6 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 19 ms
7,548 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 17 ms
7,648 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 18 ms
7,484 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int dp[1 << 16][16];

int main() {
    int n, m;
    cin >> n >> m;

    int d[16][16] = {};
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        if (a > b) swap(a, b);

        d[a][b] = max(d[a][b], c);
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            d[i][j] = d[j][i];
        }
    }

    for (int i = 0; i < n; i++) {
        dp[1 << i][i] = 1;
    }

    int r = 0;
    for (int k = 1; k < 1 << n; k++) {
        for (int i = 0; i < n; i++) {
            if (dp[k][i]) continue;
            int t = 0;
            int k1 = k & ~(1 << i);
            if (k == k1) continue;
            for (int j = 0; j < n; j++) {
                if (d[i][j] == 0 || dp[k1][j] == 0) continue;
                t = max(t, d[i][j] + dp[k1][j]);
            }
            r = max(r, dp[k][i] = t);
        }
    }

    cout << r - 1 << endl;

    return 0;
}
0