結果
| 問題 |
No.3312 Fire Engine
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-24 22:14:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 78 ms / 2,000 ms |
| コード長 | 733 bytes |
| コンパイル時間 | 2,035 ms |
| コンパイル使用メモリ | 201,360 KB |
| 実行使用メモリ | 9,984 KB |
| 最終ジャッジ日時 | 2025-10-24 22:14:56 |
| 合計ジャッジ時間 | 4,711 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 42 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N; cin >> N;
vector<vector<int>> D(N,vector<int>(N));
for(auto &h : D) for(auto &w : h) cin >> w;
int n2 = 1<<N;
vector<vector<int>> dp(n2,vector<int>(N,1001001001));
dp.at(1).at(0) = 0;
for(int i=2; i<n2; i++) for(int k=0; k<N; k++) if(i&(1<<k)){
for(int l=0; l<N; l++) if(i&(1<<k)){
if(k == l) continue;
int cost = dp.at(i-(1<<k)).at(l);
cost += D.at(l).at(k)*(N-__popcount(i-(1<<k)));
dp.at(i).at(k) = min(dp.at(i).at(k),cost);
}
}
cout << *min_element(dp.at(n2-1).begin(),dp.at(n2-1).end()) << endl;
}