結果

問題 No.753 最強王者決定戦
ユーザー parukiparuki
提出日時 2018-12-01 08:21:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 147 ms / 1,000 ms
コード長 1,950 bytes
コンパイル時間 1,973 ms
コンパイル使用メモリ 169,116 KB
実行使用メモリ 13,144 KB
最終ジャッジ日時 2023-09-09 06:46:52
合計ジャッジ時間 3,309 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
13,000 KB
testcase_01 AC 147 ms
13,020 KB
testcase_02 AC 143 ms
13,076 KB
testcase_03 AC 143 ms
13,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int bitcnt(unsigned int x) {
    x = (x & 0x55555555) + (x >> 1 & 0x55555555);
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = (x & 0x0f0f0f0f) + (x >> 4 & 0x0f0f0f0f);
    x = (x & 0x00ff00ff) + (x >> 8 & 0x00ff00ff);
    x = (x & 0x0000ffff) + (x >> 16 & 0x0000ffff);
    return (int)x;
}

const int N = 16;
ll dp[N][1 << N];
vi men[1 << N];
int in[N][N];

void solve() {
    rep(i, N)rep(j, N)cin >> in[i][j];
    rep(i, N) dp[i][1 << i] = 1;

    for (int S = 1; S < 1 << N; ++S) {
        int n = bitcnt(S);

        bool ok = false;
        rep(i, N)if (n == 1 << i)ok = true;
        if (!ok)continue;
        rep(i, N)if (S >> i & 1)men[S].push_back(i);

        for (int T = S; T > 0; T = (T - 1)&S) {
            // 3^16 = 4.30...*10^7
            int m = bitcnt(T);
            if (m != n / 2) continue;

            // C(16,8)+C(8,4)+C(4,2)+C(2,1)
            // 16*8*bin(16,8)+8*4*bin(8,4)+4*2*bin(4,2)+2*1*bin(2,1)
            const int U = S ^ T;
            each(a, men[T])each(b, men[U]) {
                int x = a < b ? in[a][b] : -in[b][a];
                if (x == 1) {
                    dp[a][S] += 2 * dp[a][T] * dp[b][U];
                }
            }
        }
    }

    rep(i, N)cout << dp[i][(1 << N) - 1] << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0