結果
| 問題 |
No.753 最強王者決定戦
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-11-10 20:41:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 908 ms / 1,000 ms |
| コード長 | 1,647 bytes |
| コンパイル時間 | 1,793 ms |
| コンパイル使用メモリ | 197,656 KB |
| 最終ジャッジ日時 | 2025-01-06 16:21:58 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
#include <bits/stdc++.h>
using ll = long long;
constexpr int N = 16;
constexpr int MASK = 1 << N;
ll memo[N][MASK];
int win[N][N];
int main()
{
for (int i = 0; i < N; i++) { std::fill(memo[i], memo[i] + MASK, -1); }
auto next_combination = [](const int mask) {
const int x = mask & (-mask), y = mask + x;
return (((mask & ~y) / x) >> 1) | y;
};
for (int i = 0; i < N; i++) {
for (int j = 0, c; j < N; j++) {
std::cin >> c;
if (j >= i) { win[i][j] = (c == 1), win[j][i] = (c == -1); }
}
}
auto dp = [&](auto&& self, const int p, const int mask, const int b) -> ll {
if (b == 1) { return mask == (1 << p) ? 1 : 0; }
if (memo[p][mask] != -1) { return memo[p][mask]; }
std::vector<int> bits;
for (int i = 0; i < N; i++) {
if (mask & (1 << i)) { bits.push_back(i); }
}
const int half = b / 2;
int subi = (1 << half) - 1;
ll ans = 0;
for (; subi < (1 << b); subi = next_combination(subi)) {
int sub = 0;
for (int i = 0; i < b; i++) {
if (subi & (1 << i)) { sub |= (1 << bits[i]); }
}
int other = mask - sub;
if (other & (1 << p)) { std::swap(sub, other); }
for (const int q : bits) {
if ((sub & (1 << q)) or (win[q][p])) { continue; }
ans += self(self, p, sub, b / 2) * self(self, q, other, b / 2);
}
}
return memo[p][mask] = ans;
};
for (int i = 0; i < N; i++) { std::cout << dp(dp, i, MASK - 1, N) << std::endl; }
return 0;
}