結果

問題 No.1284 Flip Game
ユーザー 👑 NachiaNachia
提出日時 2020-11-06 21:35:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 1,021 bytes
コンパイル時間 1,304 ms
コンパイル使用メモリ 165,216 KB
実行使用メモリ 21,872 KB
最終ジャッジ日時 2023-09-29 18:20:07
合計ジャッジ時間 3,391 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 7 ms
4,664 KB
testcase_16 AC 7 ms
4,504 KB
testcase_17 AC 24 ms
9,704 KB
testcase_18 AC 25 ms
9,528 KB
testcase_19 AC 103 ms
21,844 KB
testcase_20 AC 25 ms
9,468 KB
testcase_21 AC 24 ms
9,536 KB
testcase_22 AC 24 ms
9,472 KB
testcase_23 AC 102 ms
21,824 KB
testcase_24 AC 103 ms
21,872 KB
testcase_25 AC 105 ms
21,828 KB
testcase_26 AC 104 ms
21,764 KB
testcase_27 AC 106 ms
21,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int N;
LL C[9][9];
LL dp[1 << 18][9];
int whiten[9];
int flipped[9];
int allwhiten;

int main() {
	cin >> N;
	rep(i, N) rep(j, N) cin >> C[i][j];

	rep(i, 9) whiten[i] = 1 << (i * 2);
	rep(i, 9) flipped[i] = 1 << (i * 2 + 1);
	allwhiten = 0; rep(i, N) allwhiten |= whiten[i];
	const int arrsz = 1 << (N * 2);

	rep(i, arrsz) rep(j, N) dp[i][j] = 1000000000000;
	rep(i, N) dp[1 << (i * 2)][i] = 0;

	LL ans = 1000000000000;

	rep(i, arrsz) rep(j, N) {
		LL d = dp[i][j];
		bool ok = true;
		int newi = i; if (!(i & flipped[j])) { ok = false; newi &= ~whiten[j]; newi |= flipped[j]; }
		rep(to, N) {
			if (newi & whiten[to]) continue;
			if (to == j) continue;
			dp[newi | whiten[to]][to] = min(dp[newi | whiten[to]][to], d + C[j][to]);
			if (((newi | whiten[to]) & allwhiten) == allwhiten) ans = min(ans, dp[newi | whiten[to]][to]);
		}
	}

	cout << ans << endl;

	return 0;
}
0