結果

問題 No.1284 Flip Game
ユーザー rogi52rogi52
提出日時 2020-11-07 00:33:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,003 bytes
コンパイル時間 1,562 ms
コンパイル使用メモリ 173,428 KB
実行使用メモリ 22,012 KB
最終ジャッジ日時 2023-09-29 19:51:37
合計ジャッジ時間 3,055 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,604 KB
testcase_16 AC 4 ms
4,772 KB
testcase_17 AC 11 ms
7,968 KB
testcase_18 WA -
testcase_19 AC 39 ms
21,924 KB
testcase_20 AC 11 ms
8,244 KB
testcase_21 AC 10 ms
7,980 KB
testcase_22 AC 10 ms
8,048 KB
testcase_23 AC 39 ms
22,012 KB
testcase_24 AC 39 ms
21,872 KB
testcase_25 AC 39 ms
21,872 KB
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
#define chmin(x,y) x=min(x,y)

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

    int N; cin >> N;
    vector<vector<int>> c(N, vector<int>(N));
    rep(i,N)rep(j,N) cin >> c[i][j];

    vector<vector<vector<int>>> dp(1<<N, vector<vector<int>>(1<<N, vector<int>(N, 1e9)));
    rep(i,N) dp[0][1<<i][i] = 0;
    rep(i,1<<N)rep(j,(1<<N)-1)rep(k,N){
        if(dp[i][j][k] == (int)1e9) continue;

        rep(l,N){
            if(!(j >> l & 1) && i >> k & 1){
                int j2 = j | (1 << l);
                chmin(dp[i][j2][l], dp[i][j][k] + c[k][l]);
            }else if(!(j >> l & 1)){
                int i2 = i | (1 << k);
                int j2 = (j | (1 << l)) ^ (1 << k);
                chmin(dp[i2][j2][l], dp[i][j][k] + c[k][l]);
            }
        }
    }

    int ans = 1e9;
    rep(i,1<<N)rep(j,N) chmin(ans, dp[i][(1<<N) - 1][j]);
    cout << ans << '\n';
}
0