結果

問題 No.753 最強王者決定戦
ユーザー kwm_tkwm_t
提出日時 2023-04-05 19:28:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 626 ms / 1,000 ms
コード長 2,345 bytes
コンパイル時間 2,411 ms
コンパイル使用メモリ 213,804 KB
実行使用メモリ 7,268 KB
最終ジャッジ日時 2024-04-10 01:20:10
合計ジャッジ時間 6,135 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 614 ms
7,268 KB
testcase_01 AC 611 ms
7,268 KB
testcase_02 AC 626 ms
7,140 KB
testcase_03 AC 615 ms
7,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
int popcount(long long n) {
	n = (n & 0x5555555555555555) + (n >> 1 & 0x5555555555555555);
	n = (n & 0x3333333333333333) + (n >> 2 & 0x3333333333333333);
	n = (n & 0x0f0f0f0f0f0f0f0f) + (n >> 4 & 0x0f0f0f0f0f0f0f0f);
	n = (n & 0x00ff00ff00ff00ff) + (n >> 8 & 0x00ff00ff00ff00ff);
	n = (n & 0x0000ffff0000ffff) + (n >> 16 & 0x0000ffff0000ffff);
	n = (n & 0x00000000ffffffff) + (n >> 32 & 0x00000000ffffffff);
	return n;
}
int a[16][16];
vector<vector<long long>>v(17);
map<int, vector<long long>>mp;
vector<long long> dp(int bit) {
	if (mp.count(bit))return mp[bit];
	vector<long long>ret(16);
	int pc = popcount(bit);
	rep(i, v[pc / 2].size()) {
		int j = v[pc / 2][i];
		int k = bit ^ j;
		if (j != (j & bit))continue;
		auto x = dp(j);
		auto y = dp(k);
		rep(j, 16)rep(k, 16) {
			if (1 == a[j][k])ret[j] += x[j] * y[k];
			else ret[k] += x[j] * y[k];
		}
	}
	return mp[bit] = ret;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	rep(i, 16)rep(j, 16) cin >> a[i][j];
	rep(i, 16)rep2(j, i + 1, 16) a[j][i] -= a[i][j];
	rep(i, 17) {
		vector<long long>vec(16);
		rep(j, i)vec[j] = 1;
		sort(all(vec));
		do {
			int bit = 0;
			rep(j, 16) {
				bit *= 2;
				bit += vec[j];
			}
			v[i].push_back(bit);
		} while (next_permutation(vec.begin(), vec.end()));
	}
	rep(i, 16)rep2(j, i + 1, 16) {
		vector<long long>vec(16);
		if (1 == a[i][j])vec[i] = 2;
		else vec[j] = 2;
		mp[(1 << i) + (1 << j)] = vec;
	}
	auto get = dp((1 << 16) - 1);
	rep(i, 16) {
		cout << get[i] << endl;
	}
	return 0;
}
0