結果

問題 No.845 最長の切符
ユーザー 👑 hitonanodehitonanode
提出日時 2019-06-29 01:40:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 3,000 ms
コード長 996 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 73,188 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2023-09-14 22:56:21
合計ジャッジ時間 2,118 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 3 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,376 KB
testcase_15 AC 14 ms
4,376 KB
testcase_16 AC 58 ms
7,532 KB
testcase_17 AC 13 ms
4,376 KB
testcase_18 AC 28 ms
5,108 KB
testcase_19 AC 7 ms
4,380 KB
testcase_20 AC 61 ms
7,528 KB
testcase_21 AC 60 ms
7,576 KB
testcase_22 AC 13 ms
4,380 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 59 ms
7,480 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 11 ms
7,720 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 11 ms
7,484 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> D(N * N);
    REP(_, M)
    {
        int A, B, C;
        cin >> A >> B >> C;
        A--;
        B--;
        mmax(D[A * N + B], C);
        mmax(D[B * N + A], C);
    }

    vector<vector<int>> dp(N, vector<int>(1 << N, -1));
    REP(i, N) dp[i][1 << i] = 0;
    int ret = 0;
    REP(S, 1 << N) REP(d, N) if (((1 << d) & S) and dp[d][S] >= 0)
    {
        REP(dd, N) if (!((1 << dd) & S) and D[d * N + dd])
        {
            mmax(dp[dd][S ^ (1 << dd)], dp[d][S] + D[d * N + dd]);
            mmax(ret, dp[dd][S ^ (1 << dd)]);
        }
    }
    cout << ret << endl;
}
0