結果

問題 No.1284 Flip Game
ユーザー leaf_1415leaf_1415
提出日時 2020-11-06 23:55:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 1,284 bytes
コンパイル時間 1,725 ms
コンパイル使用メモリ 74,528 KB
実行使用メモリ 21,772 KB
最終ジャッジ日時 2023-09-29 19:46:11
合計ジャッジ時間 3,379 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 3 ms
6,024 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 3 ms
5,892 KB
testcase_14 AC 4 ms
5,852 KB
testcase_15 AC 8 ms
8,380 KB
testcase_16 AC 8 ms
8,248 KB
testcase_17 AC 34 ms
12,700 KB
testcase_18 AC 34 ms
12,704 KB
testcase_19 AC 161 ms
21,760 KB
testcase_20 AC 34 ms
12,936 KB
testcase_21 AC 34 ms
12,628 KB
testcase_22 AC 35 ms
12,700 KB
testcase_23 AC 160 ms
21,712 KB
testcase_24 AC 160 ms
21,760 KB
testcase_25 AC 160 ms
21,768 KB
testcase_26 AC 160 ms
21,740 KB
testcase_27 AC 160 ms
21,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18
#define mod 1000000007

using namespace std;

typedef long long llint;
typedef pair<llint, llint> P;

llint n;
llint c[10][10];
llint dp[1<<9][1<<9][9];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	rep(i, 0, n-1){
		rep(j, 0, n-1){
			cin >> c[i][j];
		}
	}
	
	llint N = 1<<n, ans = inf;
	rep(i, 0, N-1){
		rep(j, 0, N-1){
			rep(k, 0, n-1){
				dp[i][j][k] = inf;
			}
		}
	}
	rep(i, 0, n-1) dp[0][1<<i][i] = 0;
	
	rep(i, 0, N-1){
		rep(j, 0, N-1){
			rep(k, 0, n-1){
				rep(l, 0, n-1){
					if(j & (1<<l)) continue;
					llint nj = j | (1<<l);
					if((i & (1<<k)) == 0) nj &= ~(1<<k);
					else if(nj == N-1) ans = min(ans, dp[i][j][k] + c[k][l]);
					chmin(dp[i|(1<<k)][nj][l], dp[i][j][k] + c[k][l]);
				}
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}
0