結果

問題 No.1690 Power Grid
ユーザー ytftytft
提出日時 2021-09-25 18:41:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,504 bytes
コンパイル時間 1,908 ms
コンパイル使用メモリ 167,740 KB
実行使用メモリ 40,544 KB
最終ジャッジ日時 2023-09-18 23:08:48
合計ジャッジ時間 6,538 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 193 ms
40,412 KB
testcase_07 AC 198 ms
40,272 KB
testcase_08 AC 194 ms
40,348 KB
testcase_09 AC 193 ms
40,260 KB
testcase_10 AC 190 ms
40,408 KB
testcase_11 WA -
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 193 ms
40,204 KB
testcase_21 AC 192 ms
40,212 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int count(int a){
    int ret=0;
    while(a){
        ret+=a%2;
        a/=2;
    }
    return ret;
}

int main(){
    long long inf=1e8;
    inf*=inf;
    int N,M,K;
    cin>>N>>M>>K;
    long long A[N];
    for(int i=0;i<N;++i){
        cin>>A[i];
    }
    long long dist[N][N];
    for(int i=0;i<N;++i){
        for(int j=0;j<N;++j){
            dist[i][j]=(i==j?0:inf);
        }
    }
    for(int i=0;i<M;++i){
        long long X,Y,Z;
        cin>>X>>Y>>Z;
        --X;--Y;
        for(int j=0;j<N;++j){
            for(int k=0;k<N;++k){
                dist[j][k]=min(dist[j][k],dist[j][X]+dist[Y][k]+Z);
                dist[j][k]=min(dist[j][k],dist[j][Y]+dist[X][k]+Z);
            }
        }
    }
    long long dp[(1<<N)][N];
    for(int i=0;i<(1<<N);++i){
        for(int j=0;j<N;++j){
            if((i&(1<<j))==0){
                dp[i][j]=inf;
                continue;
            }
            if(i==(1<<j)){
                dp[i][j]=A[j];
                continue;
            }
            
            dp[i][j]=inf;
            for(int k=0;k<N;++k){
                if((j!=k)&&((i&(1<<k))!=0)){
                    dp[i][j]=min(dp[i][j],dp[i^(1<<j)][k]+dist[k][j]+A[j]);
                }
            }
        }
    }
    long long ans=inf;
    for(int i=0;i<(1<<N);++i){
        if(count(i)!=K){
            continue;
        }
        for(int j=0;j<N;++j){
            ans=min(ans,dp[i][j]);
        }
    }
    cout<<ans<<endl;
}
0