結果

問題 No.1284 Flip Game
ユーザー 👑 platinumplatinum
提出日時 2020-09-03 22:28:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 898 bytes
コンパイル時間 722 ms
コンパイル使用メモリ 74,284 KB
実行使用メモリ 8,724 KB
最終ジャッジ日時 2023-08-17 13:47:04
合計ジャッジ時間 3,181 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,160 KB
testcase_01 AC 4 ms
8,388 KB
testcase_02 AC 5 ms
8,408 KB
testcase_03 AC 4 ms
8,208 KB
testcase_04 AC 3 ms
8,208 KB
testcase_05 AC 3 ms
8,144 KB
testcase_06 AC 3 ms
8,156 KB
testcase_07 AC 4 ms
8,412 KB
testcase_08 AC 3 ms
8,456 KB
testcase_09 AC 3 ms
8,456 KB
testcase_10 AC 4 ms
8,412 KB
testcase_11 AC 4 ms
8,604 KB
testcase_12 AC 4 ms
8,480 KB
testcase_13 AC 5 ms
8,568 KB
testcase_14 AC 5 ms
8,404 KB
testcase_15 AC 9 ms
8,400 KB
testcase_16 AC 9 ms
8,412 KB
testcase_17 AC 27 ms
8,524 KB
testcase_18 AC 26 ms
8,464 KB
testcase_19 AC 95 ms
8,412 KB
testcase_20 AC 27 ms
8,392 KB
testcase_21 AC 27 ms
8,388 KB
testcase_22 AC 27 ms
8,384 KB
testcase_23 AC 95 ms
8,396 KB
testcase_24 AC 94 ms
8,472 KB
testcase_25 AC 94 ms
8,724 KB
testcase_26 AC 92 ms
8,464 KB
testcase_27 AC 94 ms
8,412 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