結果
| 問題 | No.753 最強王者決定戦 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-11-10 05:39:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 257 ms / 1,000 ms |
| コード長 | 1,287 bytes |
| コンパイル時間 | 2,172 ms |
| コンパイル使用メモリ | 196,028 KB |
| 最終ジャッジ日時 | 2025-01-06 16:19:42 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
using ll = long long;
using namespace std;
constexpr int N = 16;
array<ll, N> solve(array<array<bool, N>, N> a) {
vector<array<ll, N> > dp(1 << N);
REP (s, 1 << N) if (__builtin_popcount(__builtin_popcount(s)) == 1) {
int k = __builtin_popcount(s);
if (k == 1) {
int i = __builtin_ctz(s);
dp[s][i] = 1;
} else {
for (int t1 = 0; ; t1 = (t1 - s) & s) {
int t2 = s ^ t1;
if (__builtin_popcount(t1) == __builtin_popcount(t2)) {
REP (i, N) if (t1 & (1 << i)) {
REP (j, N) if (t2 & (1 << j)) {
dp[s][a[i][j] ? i : j] += dp[t1][i] * dp[t2][j];
}
}
}
if (t1 == s) break;
}
}
}
return dp[(1 << N) - 1];
}
int main() {
array<array<bool, N>, N> a = {};
REP (y, N) REP (x, N) {
int b; cin >> b;
if (b == 1) {
a[y][x] = true;
} else if (b == -1) {
a[x][y] = true;
}
}
auto answer = solve(a);
REP (i, N) {
cout << answer[i] << endl;
}
return 0;
}