結果

問題 No.519 アイドルユニット
ユーザー 🐬hec🐬hec
提出日時 2017-05-29 22:59:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,678 bytes
コンパイル時間 1,865 ms
コンパイル使用メモリ 178,436 KB
実行使用メモリ 12,156 KB
最終ジャッジ日時 2023-10-21 17:00:43
合計ジャッジ時間 6,323 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

// Problem Specific Parameter:

vector<int> min_cost_match(vector<vector<int>> a) {
	int n = a.size(), m = a[0].size();
	vector<int> left(n, -1), right(m, -1);
	vector<int> ofsleft(n, 0), ofsright(m, 0);
	auto cost = [&](int i, int j) { return a[i][j] + ofsleft[i] + ofsright[j];};

	rep(r, n) {
		vector<bool> s(n, false), t(m, false);
		vector<int> trace(m, -1), edge(m, r);
		s[r] = true;

		int b = -1;
		while (1) {
			int d = numeric_limits<int>::max();
			rep(j, m) if (!t[j]) d = min(d, cost(edge[j], j));
			rep(i, n) if (s[i]) ofsleft[i] -= d;
			rep(j, m) if (t[j]) ofsright[j] += d;

			rep(j, m) if (!t[j] && cost(edge[j], j) == 0) b = j;
			trace[b] = edge[b];
			int c = right[b];
			if (c < 0) break;

			s[c] = t[b] = true;
			rep(j, m) if (cost(c, j) < cost(edge[j], j)) edge[j] = c;
		}
		while (b >= 0) {
			int a = trace[b], nb = left[a];
			right[b] = a, left[a] = b, b = nb;
		}
	}
	return left;
}

int f[24][24];

int main(void) {
	int n;
	cin >> n;

	rep(i, n)rep(j, n) cin >> f[i][j];

	int ans = 0;
	rep(mask, 1 << n) {
		if (mask & 1) continue;
		if (__builtin_popcountll(mask) != n / 2) continue;

		vector<int> a, b;
		rep(i, n) {
			if (mask & (1 << i))
				a.push_back(i);
			else
				b.push_back(i);
		}

		vector<vector<int>> c(n / 2, vector<int>(n / 2, 0));

		rep(i, n / 2)rep(j, n / 2) c[i][j] = -f[a[i]][b[j]];

		vector<int> idx = min_cost_match(c);

		int cur = 0;
		rep(i, n / 2) cur += c[i][idx[i]];

		chmin(ans, cur);
	}

	cout << -ans << endl;
	return 0;
}
0