結果
問題 |
No.3158 Collect Stamps
|
ユーザー |
![]() |
提出日時 | 2025-05-23 19:38:13 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 35 ms / 2,000 ms |
コード長 | 1,297 bytes |
コンパイル時間 | 5,943 ms |
コンパイル使用メモリ | 332,880 KB |
実行使用メモリ | 8,036 KB |
最終ジャッジ日時 | 2025-05-23 19:38:20 |
合計ジャッジ時間 | 6,515 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
#include <atcoder/all> #include <bits/stdc++.h> #define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) using namespace atcoder; using namespace std; typedef long long ll; int inf = 1e9; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, k; cin >> n >> m >> k; int dp[1 << n][n]; rep(i, 0, 1 << n) rep(j, 0, n) dp[i][j] = inf; rep(i, 0, k) { int x; cin >> x, x--; dp[1 << x][x] = 0; } vector<vector<int>> a(n, vector<int>(n)); rep(i, 0, n) rep(j, 0, n) cin >> a[i][j]; rep(i, 0, n) rep(j, i + 1, n) swap(a[i][j], a[j][i]); int ans = inf; vector<pair<int, int>> order; rep(i, 1, 1 << n) order.emplace_back(__builtin_popcount(i), i); sort(order.begin(), order.end()); for (auto [_, mask] : order) { rep(i, 0, n) { if (dp[mask][i] == inf) continue; rep(j, 0, n) { if (mask & (1 << j)) continue; dp[mask | (1 << j)][j] = min(dp[mask][i] + a[i][j], dp[mask | (1 << j)][j]); } } } rep(i, 0, 1 << n) { if (__builtin_popcount(i) == m) { rep(j, 0, n) { ans = min(ans, dp[i][j]); } } } cout << ans << endl; }