結果

問題 No.845 最長の切符
ユーザー ttttan2ttttan2
提出日時 2019-06-28 23:03:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 579 ms / 3,000 ms
コード長 1,509 bytes
コンパイル時間 1,293 ms
コンパイル使用メモリ 149,756 KB
実行使用メモリ 12,640 KB
最終ジャッジ日時 2023-09-14 22:35:20
合計ジャッジ時間 5,754 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 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,380 KB
testcase_06 AC 1 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 9 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 107 ms
5,860 KB
testcase_16 AC 563 ms
12,468 KB
testcase_17 AC 107 ms
5,644 KB
testcase_18 AC 248 ms
7,804 KB
testcase_19 AC 47 ms
4,992 KB
testcase_20 AC 560 ms
12,608 KB
testcase_21 AC 542 ms
12,468 KB
testcase_22 AC 108 ms
5,684 KB
testcase_23 AC 21 ms
4,376 KB
testcase_24 AC 579 ms
12,572 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 8 ms
12,640 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 9 ms
12,564 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;cin>>n>>m;
    ll d[n+1][n+1];
    rep(i,0,n+1){
        rep(j,0,n+1)d[i][j]=-1;
    }
    rep(i,0,m){
        ll a,b,c;cin>>a>>b>>c;
        d[a][b]=max(d[a][b],c);
        d[b][a]=d[a][b];
    }
    vector<ll> v[n+1];
    rep(i,1,n+1){
        rep(j,1,n+1){
            if(d[i][j]!=-1)v[i].push_back(j);
        }
    }
    ll u=pow(2,n);
    ll dp[u][n+1];
    rep(i,0,u)rep(j,0,n+1)dp[i][j]=-1;
    int now=1;
    rep(i,0,n){
        dp[now][i+1]=0;
        now*=2;
    }
    rep(i,1,u){
        rep(k,1,n+1){
            if(dp[i][k]==-1)continue;
        rep(j,0,n){
            int r=pow(2,j);
            int t=i/r;
            if(t%2==1)continue;
            if(d[k][j+1]==-1)continue;
            dp[i+r][j+1]=max(dp[i+r][j+1],dp[i][k]+d[k][j+1]);
        }
        }
    }
    ll ans=0;
    rep(i,0,u)rep(j,1,n+1)ans=max(ans,dp[i][j]);
    cout<<ans<<endl;
}
0