結果
| 問題 |
No.3158 Collect Stamps
|
| コンテスト | |
| ユーザー |
Cafe1942
|
| 提出日時 | 2025-05-23 19:46:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,951 bytes |
| コンパイル時間 | 945 ms |
| コンパイル使用メモリ | 112,804 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-05-23 19:46:34 |
| 合計ジャッジ時間 | 2,828 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 6 RE * 4 |
ソースコード
#include <iostream>
#include <iomanip>//小数点出力用
//cout << fixed << setprecision(10) << ans;
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
using ll = long long;
using namespace std;
#define modP7 1'000'000'007
#define modP 998244353
bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); }
int clk4(int num) { return (num - 2) * (num % 2); }
void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); }
bool include3(string S) {
for (int i = 0;i < S.size();i++) {
if (S[i] == 0x33) {
return 1;
}
}
return 0;
}
bool multi3(string S) {
int res = 0;
for (int i = 0;i < S.size();i++) {
res += (int)(S[i] - 0x30);
}
if (res % 3 == 0) {
return 1;
}
return 0;
}
int main() {
int N, M, K;
cin >> N >> M >> K;
bool G[20] = { 0 };
for (int i = 0;i < K;i++) {
int A;
cin >> A;
G[A] = 1;
}
int T[20][20];
for (int i = 1;i <= N;i++) {
for (int j = 1;j <= N;j++) {
cin >> T[i][j];
}
}
int route[6] = { 1,2,3,4,5,6 };
int best = 1e9;
while (1) {
do {
int res = 0;
for (int j = 1;j < M;j++) {
res += T[route[j - 1]][route[j]];
}
if (!G[route[M - 1]]) {
res += T[route[M - 1]][route[M]];
}
best = min(best, res);
} while (next_permutation(route, route + M + 1));
{
int i = M;
while (route[i] == N - (M - i)) {
i--;
if (i == -1) {
cout << best;
return 0;
}
}
route[i]++;
i++;
for (;i <= M;i++) {
route[i] = route[i - 1] + 1;
}
}
}
return 0;
}
Cafe1942