結果
| 問題 | No.3158 Collect Stamps |
| コンテスト | |
| ユーザー |
クロさん
|
| 提出日時 | 2025-12-09 22:36:57 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 15 ms / 2,000 ms |
| コード長 | 1,357 bytes |
| 記録 | |
| コンパイル時間 | 4,380 ms |
| コンパイル使用メモリ | 257,824 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-12-09 22:37:03 |
| 合計ジャッジ時間 | 6,000 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
static const double pi = 3.141592653589793;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ll imod = 998244353;
using mint = modint998244353;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
ll P(ll x, ll n) {
ll ret = 1;
while (n > 0) {
if (n & 1) ret *= x;
x *= x;
n >>= 1;
}
return ret;
}
void seek(bool f){
cout << (f ? "Yes" : "No") << endl;
}
int main(){
int N, M, K;
cin >> N >> M >> K;
vector<int> OK(N, 0);
rep(i, K){
int x;
cin >> x;
x--;
OK[x] = 1;
}
vector<vector<int>> T(N, vector<int> (N));
rep(i, N){
rep(j, N){
cin >> T[i][j];
}
}
vector<int> order(N, 0);
rep(i, M){
order[i] = 1;
}
sort(order.begin(), order.end());
int ans = 1e9;
do{
vector<int> A;
rep(i, N){
if(order[i] == 1){
A.push_back(i);
}
}
do{
int res = 0;
rep(j, M - 1){
res += T[A[j]][A[j + 1]];
}
if(OK[A[M - 1]] == 0){
int add = 1e9;
rep(k, N){
if(OK[k] == 1){
add = min(add, T[A[M - 1]][k]);
}
}
res += add;
}
ans = min(ans, res);
}while(next_permutation(A.begin(), A.end()));
}while(next_permutation(order.begin(), order.end()));
cout << ans << endl;
}
クロさん