結果
| 問題 |
No.1284 Flip Game
|
| コンテスト | |
| ユーザー |
trineutron
|
| 提出日時 | 2020-11-24 01:25:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 14 ms / 2,000 ms |
| コード長 | 1,073 bytes |
| コンパイル時間 | 1,876 ms |
| コンパイル使用メモリ | 197,120 KB |
| 最終ジャッジ日時 | 2025-01-16 05:21:47 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
const int inf = 2000000000;
int n;
cin >> n;
vector c(n, vector(n, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> c[i][j];
}
}
vector<int> power(n + 1, 1);
int s = 1;
for (int i = 0; i < n; i++) {
s *= 3;
power[i + 1] = s;
}
vector cost(s, vector(n, inf));
for (int i = 0; i < n; i++) {
cost[power[i]][i] = 0;
}
for (int i = 0; i < s; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
if (j == k) continue;
if (i / power[k] % 3 == 2) continue;
int newi = i + power[k];
cost[newi][k] = min(cost[newi][k], cost[i][j] + c[j][k]);
}
}
}
int ans = inf;
for (int i = 0; i < n; i++) {
ans = min({ans,
cost[s - 1][i],
cost[s - 1 - power[i]][i],
cost[s - 1 - 2 * power[i]][i]});
}
cout << ans << endl;
}
trineutron