結果

問題 No.1284 Flip Game
ユーザー 👑 platinumplatinum
提出日時 2020-09-03 22:28:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 898 bytes
コンパイル時間 781 ms
コンパイル使用メモリ 74,700 KB
実行使用メモリ 8,472 KB
最終ジャッジ日時 2024-05-04 20:25:54
合計ジャッジ時間 2,444 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,228 KB
testcase_01 AC 3 ms
8,316 KB
testcase_02 AC 5 ms
8,224 KB
testcase_03 AC 3 ms
8,440 KB
testcase_04 AC 4 ms
8,448 KB
testcase_05 AC 4 ms
8,320 KB
testcase_06 AC 5 ms
8,396 KB
testcase_07 AC 5 ms
8,428 KB
testcase_08 AC 4 ms
8,320 KB
testcase_09 AC 5 ms
8,328 KB
testcase_10 AC 5 ms
8,436 KB
testcase_11 AC 4 ms
8,320 KB
testcase_12 AC 5 ms
8,396 KB
testcase_13 AC 6 ms
8,260 KB
testcase_14 AC 5 ms
8,320 KB
testcase_15 AC 9 ms
8,280 KB
testcase_16 AC 9 ms
8,252 KB
testcase_17 AC 20 ms
8,232 KB
testcase_18 AC 20 ms
8,248 KB
testcase_19 AC 62 ms
8,392 KB
testcase_20 AC 20 ms
8,356 KB
testcase_21 AC 19 ms
8,336 KB
testcase_22 AC 20 ms
8,472 KB
testcase_23 AC 63 ms
8,356 KB
testcase_24 AC 62 ms
8,320 KB
testcase_25 AC 62 ms
8,240 KB
testcase_26 AC 61 ms
8,320 KB
testcase_27 AC 62 ms
8,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;
const int Max_N = 12;
const int Max_S = 1e5;
const int INF = 2e9+5;

int N, M, fin;
int c[Max_N][Max_N];
int dp[Max_S][Max_N];

int rec(int s, int v){
	if(dp[s][v]!=INF) return dp[s][v];
	int res=INF;
	rep(u,N){
		if(u==v and s!=fin) continue;
		int div=pow(M,u);
		if(s/div%M==0) continue;
		int ns=s-pow(M,v);
		res=min(res,rec(ns,u)+c[u][v]);
	}
	return dp[s][v]=res;
}

int main(){
	cin >> N;
	M=3;
	fin=pow(M,N)-1;
	rep(i,N){
		rep(j,N) cin >> c[i][j];
	}
	rep(i,Max_S){
		rep(j,Max_N) dp[i][j]=INF;
	}
	rep(i,N){
		int st=pow(3,i);
		dp[st][i]=0;
	}
	rep(i,N) rec(fin,i);
	int ans=INF;
	rep(i,N) ans=min(ans,dp[fin][i]);
	cout << ans << endl;

	return 0;
}
0