結果

問題 No.3312 Fire Engine
コンテスト
ユーザー tau1235
提出日時 2025-10-24 22:28:44
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 548 ms / 2,000 ms
コード長 727 bytes
コンパイル時間 3,004 ms
コンパイル使用メモリ 293,480 KB
実行使用メモリ 23,712 KB
最終ジャッジ日時 2025-10-24 22:29:07
合計ジャッジ時間 15,271 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
  using ll=long long;
  ll inf=1e18;
  int n;
  cin>>n;
  vector<vector<int>> d(n,vector<int>(n));
  for (int i=0;i<n;i++) for (int j=0;j<n;j++) cin>>d[i][j];
  vector<vector<ll>> dp(1<<n,vector<ll>(n,inf));
  priority_queue<tuple<ll,int,int>> q;
  q.push({0,1,0});
  while (!q.empty()){
    auto [dist,i,v]=q.top();
    q.pop();
    if (dp[i][v]!=inf) continue;
    dist*=-1;
    dp[i][v]=dist;
    for (int u=0;u<n;u++){
      int ni=i|(1<<u);
      if (ni==i) continue;
      ll nd=dist;
      int p=n+1-__popcount(ni);
      nd+=p*d[v][u];
      q.push({-nd,ni,u});
    }
  }
  ll ans=inf;
  for (int i=0;i<n;i++) ans=min(ans,dp[(1<<n)-1][i]);
  cout<<ans<<endl;
}
0