結果

問題 No.1284 Flip Game
ユーザー kyoprounokyoprouno
提出日時 2020-11-07 01:25:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 683 ms / 2,000 ms
コード長 1,838 bytes
コンパイル時間 2,008 ms
コンパイル使用メモリ 179,724 KB
実行使用メモリ 50,408 KB
最終ジャッジ日時 2023-09-29 19:55:22
合計ジャッジ時間 8,139 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 7 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 7 ms
4,380 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 29 ms
5,512 KB
testcase_16 AC 29 ms
5,460 KB
testcase_17 AC 140 ms
13,948 KB
testcase_18 AC 140 ms
13,952 KB
testcase_19 AC 681 ms
50,408 KB
testcase_20 AC 139 ms
13,844 KB
testcase_21 AC 140 ms
14,004 KB
testcase_22 AC 140 ms
13,828 KB
testcase_23 AC 682 ms
50,244 KB
testcase_24 AC 683 ms
50,132 KB
testcase_25 AC 681 ms
50,088 KB
testcase_26 AC 683 ms
50,256 KB
testcase_27 AC 682 ms
50,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){//popcount%2
	return __builtin_parity(x);
}



template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e18;

int main(){
    ll n;
    cin >> n;
    vector<vector<ll>> c(n,vector<ll>(n));
    rep(i,n) rep(j,n){
        cin >> c[i][j];
    }
    ll ans=INF;
    vector<vector<ll>> dp(1<<(2*n),vector<ll>(2*n,INF));
    rep(i,n){
        dp[(1<<i)][i]=0;
    }
    for(ll s=1;s<(1<<(2*n));s++){
        rep(t,2*n){
            if((s>>t)%2==0) continue;
            rep(u,2*n){
                if((s>>u)%2==0) continue;
                if(t==u) continue;
                if(t%n==u%n) continue;
                dp[s][u]=min(dp[s][u],dp[s^(1<<u)][t]+c[t%n][u%n]);
            }
        }
    }
    ll all=(1<<(2*n));
    rep(i,n){
        ans=min(ans,dp[all-1][i]);
        ans=min(ans,dp[all-1][i+n]);
        ans=min(ans,dp[(all-1)^(1<<i)][i]);
        ans=min(ans,dp[(all-1)^(1<<(i+n))][i]);
        ans=min(ans,dp[(all-1)^(1<<i)][i+n]);
        ans=min(ans,dp[(all-1)^(1<<(i+n))][i+n]);
    }
    cout << ans << endl;
    return 0;
}
0