結果

問題 No.1284 Flip Game
ユーザー chocoruskchocorusk
提出日時 2020-11-11 00:00:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,733 bytes
コンパイル時間 1,181 ms
コンパイル使用メモリ 127,408 KB
実行使用メモリ 22,100 KB
最終ジャッジ日時 2023-09-30 00:16:48
合計ジャッジ時間 2,411 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,452 KB
testcase_01 AC 2 ms
7,488 KB
testcase_02 AC 3 ms
13,624 KB
testcase_03 AC 2 ms
5,460 KB
testcase_04 AC 1 ms
5,408 KB
testcase_05 AC 1 ms
5,444 KB
testcase_06 AC 2 ms
5,440 KB
testcase_07 AC 2 ms
7,452 KB
testcase_08 AC 1 ms
7,432 KB
testcase_09 AC 2 ms
9,496 KB
testcase_10 AC 2 ms
9,500 KB
testcase_11 AC 2 ms
11,536 KB
testcase_12 AC 3 ms
11,540 KB
testcase_13 AC 3 ms
13,672 KB
testcase_14 AC 3 ms
13,760 KB
testcase_15 AC 3 ms
15,808 KB
testcase_16 AC 4 ms
15,812 KB
testcase_17 AC 7 ms
18,200 KB
testcase_18 AC 8 ms
18,308 KB
testcase_19 AC 20 ms
21,824 KB
testcase_20 AC 6 ms
18,192 KB
testcase_21 AC 7 ms
18,388 KB
testcase_22 AC 6 ms
18,196 KB
testcase_23 AC 20 ms
21,780 KB
testcase_24 AC 21 ms
21,772 KB
testcase_25 AC 18 ms
21,836 KB
testcase_26 AC 17 ms
21,972 KB
testcase_27 AC 18 ms
22,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
using ll=long long;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    ll c[10][10];
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cin>>c[i][j];
        }
    }
    const ll INF=1e18;
    ll dp[9][1<<18];
    for(int i=0; i<n; i++) fill(dp[i], dp[i]+(1<<(2*n)), INF);
    for(int i=0; i<n; i++){
        dp[i][1<<(2*i)]=0;
    }
    for(int i=1; i<(1<<(2*n)); i++){
        for(int j=0; j<n; j++){
            if(dp[j][i]==INF) continue;
            int u=((i>>(2*j))&3);
            for(int k=0; k<n; k++){
                int t=((i>>(2*k))&3);
                if(t&1) continue;
                if(u==1){
                    dp[k][i^(1<<(2*k))^(3<<(2*j))]=min(dp[k][i^(1<<(2*k))^(3<<(2*j))], dp[j][i]+c[j][k]);
                }else{
                    dp[k][i^(1<<(2*k))]=min(dp[k][i^(1<<(2*k))], dp[j][i]+c[j][k]);
                }
            }
        }
    }
    ll ans=INF;
    for(int i=0; i<n; i++){
        for(int j=0; j<(1<<(2*n)); j++){
            bool ok=1;
            for(int k=0; k<n; k++){
                if(!(j&(1<<(2*k)))){
                    ok=0;break;
                }
            }
            if(ok) ans=min(ans, dp[i][j]);
        }
    }
    cout<<ans<<endl;
    return 0;
}
0