結果

問題 No.845 最長の切符
ユーザー jelljell
提出日時 2019-06-29 10:42:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 3,000 ms
コード長 1,452 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 166,264 KB
実行使用メモリ 7,984 KB
最終ジャッジ日時 2023-09-14 23:01:24
合計ジャッジ時間 3,007 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 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,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,504 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 9 ms
4,424 KB
testcase_16 AC 36 ms
7,984 KB
testcase_17 AC 9 ms
4,420 KB
testcase_18 AC 19 ms
7,556 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 36 ms
7,744 KB
testcase_21 AC 36 ms
7,708 KB
testcase_22 AC 9 ms
4,400 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 36 ms
7,744 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 36 ms
7,728 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 36 ms
7,892 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64=int_fast64_t;
using pii=pair<int,int>;
template <class T> constexpr T inf=numeric_limits<T>::max() / (T)2;
template <class T> using minheap=priority_queue<T,vector<T>,greater<T>>;
#define fir first
#define sec second
#define mkp make_pair
#define mkt make_tuple
#define emb emplace_back
#define all(v) begin(v),end(v)
i64 binry(i64 ok, i64 ng, const function<bool(i64)> &f) {
    while(abs(ok-ng)>1) {
        i64 mid=(ok+ng)/2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

int n,m;
int di[20][20];
int dp[1<<16][17];

signed main() {
    cin>>n>>m;

    for(int i=0; i<n; ++i) {
        for(int j=0; j<i; ++j) {
            di[i][j]=di[j][i]=-1e9;
        }
    }
    for(int i=0; i<m; ++i) {
        int u,v,c; cin>>u>>v>>c;
        --u,--v;
        di[v][u]=di[u][v]=max(di[u][v],c);
    }

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

    for(int h=0; h<1<<n; ++h) {
        for(int j=0; j<n; ++j) {
            if(h>>j&1) continue;
            for(int k=0; k<n; ++k) {
                if(h>>k&1) {
                    dp[h|1<<j][j]=max(dp[h|1<<j][j],dp[h][k]+di[k][j]);
                }
            }
        }
    }

    int ans=0;
    for(int i=0; i<n; ++i) {
        for(int h=0; h<1<<n; ++h) {
            ans=max(ans,dp[h][i]);
        }
    }
    cout<<ans<<endl;
}
0