結果

問題 No.3158 Collect Stamps
ユーザー karinohito
提出日時 2025-05-24 17:19:21
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 3,061 ms
コンパイル使用メモリ 289,248 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-24 17:19:26
合計ジャッジ時間 4,628 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;



int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

	ll N,M,K;
	cin>>N>>M>>K;
	vector<bool> GL(N);
	for(int i=0;i<K;i++){
		int A;
		cin>>A;
		GL[A-1]=1;
	}
	vector<vector<ll>> T(N,vector<ll>(N));
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)cin>>T[i][j];

	vector<ll> P(N,-1);
	for(int i=0;i<M;i++)P[i]=i;
	sort(P.begin(),P.end());
	ll an=1e18;
	do{
		vector<int> D(M);
		for(int i=0;i<N;i++)if(P[i]!=-1)D[P[i]]=i;
		if(GL[D[M-1]]){
			ll res=0;
			for(int j=0;j<M-1;j++){
				res+=T[D[j]][D[j+1]];
			}
			an=min(an,res);
		}
	}while(next_permutation(P.begin(),P.end()));
	cout<<an<<endl;
}
0