結果

問題 No.753 最強王者決定戦
ユーザー kimiyukikimiyuki
提出日時 2018-11-10 05:39:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 243 ms / 1,000 ms
コード長 1,287 bytes
コンパイル時間 4,740 ms
コンパイル使用メモリ 200,736 KB
実行使用メモリ 11,328 KB
最終ジャッジ日時 2023-08-14 05:51:41
合計ジャッジ時間 5,273 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 243 ms
11,328 KB
testcase_01 AC 243 ms
10,204 KB
testcase_02 AC 243 ms
11,172 KB
testcase_03 AC 242 ms
11,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0