提出 #64123310
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
// #define DEBUG
int N, M;
int A[11][11];
bool give[11][11];
int ans = INT_MAX;
int sum = 0;
bool hasRun[11];
void dfs(
int dep,
int lastRunner)
{
if (dep == N)
{
ans = min(ans, sum);
return;
}
for (int i = 1; i <= N; i++)
{
// もう走ってる
if(hasRun[i]){
continue;
}
// 噂があるので渡せない
if (give[i][lastRunner])
{
continue;
}
hasRun[i] = true;
sum += A[i][dep + 1];
dfs(dep + 1, i);
hasRun[i] = false;
sum -= A[i][dep + 1];
}
}
int main()
{
#ifdef DEBUG
freopen("input/in.txt", "r", stdin);
#endif
cin >> N;
for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= N; j++)
{
cin >> A[i][j];
}
}
cin >> M;
for (int i = 0; i < M; i++)
{
int x, y;
cin >> x >> y;
give[x][y] = true;
give[y][x] = true;
}
dfs(0, 0);
if (ans == INT_MAX)
{
cout << -1 << endl;
}
else
{
cout << ans << endl;
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | 032 - AtCoder Ekiden(★3) |
| ユーザ | sbknk |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 3 |
| コード長 | 1337 Byte |
| 結果 | AC |
| 実行時間 | 93 ms |
| メモリ | 3648 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 3 / 3 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
| All | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 10_small_n_01.txt, 10_small_n_02.txt, 10_small_n_03.txt, 50_random_01.txt, 50_random_02.txt, 50_random_03.txt, 50_random_04.txt, 50_random_05.txt, 50_random_06.txt, 50_random_07.txt, 50_random_08.txt, 50_random_09.txt, 50_random_10.txt, 50_random_11.txt, 50_random_12.txt, 50_random_13.txt, 50_random_14.txt, 50_random_15.txt, 60_max_m_01.txt, 60_max_m_02.txt, 60_min_m_01.txt, 60_min_m_02.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_01.txt | AC | 1 ms | 3444 KiB |
| 00_sample_02.txt | AC | 1 ms | 3560 KiB |
| 00_sample_03.txt | AC | 1 ms | 3428 KiB |
| 10_small_n_01.txt | AC | 1 ms | 3648 KiB |
| 10_small_n_02.txt | AC | 1 ms | 3492 KiB |
| 10_small_n_03.txt | AC | 1 ms | 3436 KiB |
| 50_random_01.txt | AC | 1 ms | 3488 KiB |
| 50_random_02.txt | AC | 1 ms | 3468 KiB |
| 50_random_03.txt | AC | 1 ms | 3460 KiB |
| 50_random_04.txt | AC | 1 ms | 3496 KiB |
| 50_random_05.txt | AC | 1 ms | 3512 KiB |
| 50_random_06.txt | AC | 1 ms | 3488 KiB |
| 50_random_07.txt | AC | 1 ms | 3492 KiB |
| 50_random_08.txt | AC | 1 ms | 3492 KiB |
| 50_random_09.txt | AC | 1 ms | 3448 KiB |
| 50_random_10.txt | AC | 1 ms | 3452 KiB |
| 50_random_11.txt | AC | 1 ms | 3496 KiB |
| 50_random_12.txt | AC | 1 ms | 3556 KiB |
| 50_random_13.txt | AC | 1 ms | 3572 KiB |
| 50_random_14.txt | AC | 1 ms | 3492 KiB |
| 50_random_15.txt | AC | 1 ms | 3432 KiB |
| 60_max_m_01.txt | AC | 1 ms | 3492 KiB |
| 60_max_m_02.txt | AC | 1 ms | 3572 KiB |
| 60_min_m_01.txt | AC | 93 ms | 3460 KiB |
| 60_min_m_02.txt | AC | 93 ms | 3440 KiB |