結果

問題 No.845 最長の切符
ユーザー jelljell
提出日時 2019-06-29 10:33:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,512 bytes
コンパイル時間 1,980 ms
コンパイル使用メモリ 165,576 KB
実行使用メモリ 8,000 KB
最終ジャッジ日時 2023-09-14 23:01:17
合計ジャッジ時間 3,585 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
        di[--u][--v]=max(di[u][v],c);
        di[v][u]=di[u][v];
    }

    for(int i=0; i<n; ++i) {
        for(int j=0; j<n; ++j) {
            for(int s=0; s<1<<n; ++s) {
                dp[s][j]=-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