結果

問題 No.519 アイドルユニット
ユーザー furonfuron
提出日時 2023-10-26 23:30:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 1,000 ms
コード長 1,662 bytes
コンパイル時間 1,573 ms
コンパイル使用メモリ 130,200 KB
実行使用メモリ 134,488 KB
最終ジャッジ日時 2023-10-26 23:30:59
合計ジャッジ時間 3,567 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
134,488 KB
testcase_01 AC 76 ms
134,488 KB
testcase_02 AC 23 ms
36,112 KB
testcase_03 AC 4 ms
5,452 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 5 ms
5,452 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 AC 4 ms
5,452 KB
testcase_14 AC 5 ms
5,452 KB
testcase_15 AC 5 ms
5,452 KB
testcase_16 AC 4 ms
5,452 KB
testcase_17 AC 4 ms
5,452 KB
testcase_18 AC 4 ms
5,452 KB
testcase_19 AC 5 ms
5,452 KB
testcase_20 AC 4 ms
5,452 KB
testcase_21 AC 5 ms
5,452 KB
testcase_22 AC 5 ms
5,452 KB
testcase_23 AC 5 ms
5,452 KB
testcase_24 AC 8 ms
11,584 KB
testcase_25 AC 9 ms
11,584 KB
testcase_26 AC 9 ms
11,584 KB
testcase_27 AC 9 ms
11,584 KB
testcase_28 AC 9 ms
11,584 KB
testcase_29 AC 76 ms
134,488 KB
testcase_30 AC 75 ms
134,488 KB
testcase_31 AC 75 ms
134,488 KB
testcase_32 AC 74 ms
134,488 KB
testcase_33 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream> 
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <queue>
#include <map>
#include <bitset>
#include <set>
#include <stack>
#include <numeric>
#include <unordered_map>
#include <random>

using namespace std;

using ll = long long;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using vs = vector<string>;
using pii = pair<int, int>; using vpii = vector<pii>;
using pil = pair<int, ll>; using vpil = vector<pil>;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using pdd = pair<double, double>; using vpdd = vector<pdd>;
const int inf = (1 << 30) - 1;
const ll INF = 1LL << 60;
//const int MOD = 1000000007;
const int MOD = 998244353;

template<typename T> inline bool chmax(T& a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T& a, T b) { return ((a > b) ? (a = b, true) : (false)); }


int main() {
	int n;
	cin >> n;
	vvi f(n, vi(n, 0));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int x;
			cin >> x;
			f[i][j] = f[j][i] = x;
		}
	}

	vl dp(1 << n, -1);
	dp[0] = 0;

	for (int b = 0; b < (1 << n) - 1; b++) {
		if (dp[b] == -1) continue;
		int x = -1;
		for (int i = 0; i < n; i++) {
			if ((b & (1 << i)) == 0) {
				x = i;
				break;
			}
		}
		for (int i = 0; i < n; i++) {
			if ((b & (1 << i)) == 0) {
				int to = b | (1 << x) | (1 << i);
				chmax(dp[to], dp[b] + f[x][i]);
			}
		}
	}

	cout << dp[(1 << n) - 1] << endl;


	return 0;
}
0