結果
| 問題 | No.3312 Fire Engine |
| コンテスト | |
| ユーザー |
tau1235
|
| 提出日時 | 2026-07-18 07:33:46 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 390 ms / 2,000 ms |
| + 677µs | |
| コード長 | 735 bytes |
| 記録 | |
| コンパイル時間 | 3,232 ms |
| コンパイル使用メモリ | 354,000 KB |
| 実行使用メモリ | 22,636 KB |
| 最終ジャッジ日時 | 2026-07-18 07:33:59 |
| 合計ジャッジ時間 | 12,828 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 42 |
ソースコード
#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-__builtin_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;
}
tau1235