結果
| 問題 |
No.3158 Collect Stamps
|
| コンテスト | |
| ユーザー |
SnowBeenDiding
|
| 提出日時 | 2025-05-23 19:27:55 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,239 bytes |
| コンパイル時間 | 6,555 ms |
| コンパイル使用メモリ | 333,748 KB |
| 実行使用メモリ | 8,036 KB |
| 最終ジャッジ日時 | 2025-05-23 19:28:18 |
| 合計ジャッジ時間 | 6,861 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 24 |
ソースコード
#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];
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;
}
SnowBeenDiding