結果
| 問題 |
No.3312 Fire Engine
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2025-10-24 21:57:27 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 2,000 ms |
| コード長 | 1,369 bytes |
| コンパイル時間 | 2,897 ms |
| コンパイル使用メモリ | 297,988 KB |
| 実行使用メモリ | 11,864 KB |
| 最終ジャッジ日時 | 2025-10-24 21:57:32 |
| 合計ジャッジ時間 | 4,911 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 42 |
ソースコード
#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
ll dp[1 << 16][16];
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
constexpr long long INF = 1002003004005006007;
rep(s, 1 << 16) rep(u, 16) dp[s][u] = INF;
int n;
cin >> n;
int d[16][16];
rep(i, n) rep(j, n) cin >> d[i][j];
rep(k, n) rep(i, n) rep(j, n) chmin(d[i][j], d[i][k] + d[k][j]);
dp[1][0] = 0;
rep(s, 1 << n) {
int rest = n - popcount(0U + s);
rep(u, n) if (ll now = dp[s][u]; now != INF) {
rep(v, n) if (~s >> v & 1) {
chmin(dp[s | 1 << v][v], now + d[u][v] * rest);
}
}
}
ll ans = INF;
rep(u, n) chmin(ans, dp[(1 << n) - 1][u]);
cout << ans << '\n';
}
Kude