結果

問題 No.1284 Flip Game
ユーザー trineutrontrineutron
提出日時 2020-11-24 01:25:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,073 bytes
コンパイル時間 2,042 ms
コンパイル使用メモリ 204,516 KB
実行使用メモリ 4,612 KB
最終ジャッジ日時 2023-10-01 00:42:56
合計ジャッジ時間 3,864 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 13 ms
4,416 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 13 ms
4,388 KB
testcase_24 AC 13 ms
4,376 KB
testcase_25 AC 13 ms
4,612 KB
testcase_26 AC 13 ms
4,420 KB
testcase_27 AC 13 ms
4,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0