結果

問題 No.1937 Various Tournament
ユーザー shinchanshinchan
提出日時 2022-05-13 22:46:30
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 2,539 bytes
コンパイル時間 2,252 ms
コンパイル使用メモリ 208,824 KB
実行使用メモリ 14,064 KB
最終ジャッジ日時 2023-09-29 08:21:45
合計ジャッジ時間 12,422 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 262 ms
13,936 KB
testcase_02 AC 262 ms
13,876 KB
testcase_03 AC 263 ms
13,776 KB
testcase_04 AC 263 ms
13,768 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 263 ms
13,864 KB
testcase_07 AC 261 ms
13,856 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 262 ms
13,820 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 261 ms
13,936 KB
testcase_12 AC 262 ms
13,932 KB
testcase_13 AC 262 ms
13,908 KB
testcase_14 AC 262 ms
13,864 KB
testcase_15 AC 261 ms
13,760 KB
testcase_16 AC 261 ms
13,936 KB
testcase_17 AC 262 ms
14,064 KB
testcase_18 AC 262 ms
14,000 KB
testcase_19 AC 263 ms
13,856 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 262 ms
13,940 KB
testcase_23 AC 261 ms
13,944 KB
testcase_24 AC 261 ms
14,028 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 261 ms
13,876 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 262 ms
13,936 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 260 ms
13,816 KB
testcase_31 AC 260 ms
13,836 KB
testcase_32 AC 263 ms
13,780 KB
testcase_33 AC 263 ms
13,812 KB
testcase_34 AC 262 ms
13,784 KB
testcase_35 AC 263 ms
13,836 KB
testcase_36 AC 262 ms
13,880 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 264 ms
13,812 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 262 ms
13,944 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 262 ms
13,836 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<vector<int>> s(n, vector<int> (n, 0));
    rep(i, n) rep(j, n) {
        cin >> s[i][j];
    }
    ll mask = (1 << n);
    vector<vector<ll>> dp(mask, vector<ll> (n, 0));
    rep(i, n) dp[1 << i][i] = 1;
    for(ll bit = 1; bit < mask; bit++) {

        ll bb = __builtin_popcount(bit);
        if(bb == 2) {
            for(ll t = bit; t > 0; t = (t - 1) & bit) {
                if(__builtin_popcount(t) != 1) continue;
                ll id1, id2;
                for(int i = 0; i < n; i ++) if(t >> i & 1) {
                    id1 = i;
                }
                for(int i = 0; i < n; i ++) if((bit - t) >> i & 1) {
                    id2 = i;
                }
                dp[bit][(s[id1][id2] ? id1 : id2)] += dp[t][id1] * dp[bit - t][id2];
            }
        } else if(bb == 4) {
            for(ll t = bit; t > 0; t = (t - 1) & bit) {
                if(__builtin_popcount(t) != 2) continue;
                for(int i = 0; i < n; i ++) if(t >> i & 1) {
                    for(int j = 0; j < n; j ++) if((bit - t) >> j & 1) {
                        dp[bit][(s[i][j] ? i : j)] += dp[t][i] * dp[bit - t][j];
                    }
                }
            }
        } else if(bb == 8) {
            for(ll t = bit; t > 0; t = (t - 1) & bit) {
                if(__builtin_popcount(t) != 4) continue;
                for(int i = 0; i < n; i ++) if(t >> i & 1) {
                    for(int j = 0; j < n; j ++) if((bit - t) >> j & 1) {
                        dp[bit][(s[i][j] ? i : j)] += dp[t][i] * dp[bit - t][j];
                    }
                }
            }
        } else if(bb == 16) {
            for(ll t = bit; t > 0; t = (t - 1) & bit) {
                if(__builtin_popcount(t) != 8) continue;
                for(int i = 0; i < n; i ++) if(t >> i & 1) {
                    for(int j = 0; j < n; j ++) if((bit - t) >> j & 1) {
                        dp[bit][(s[i][j] ? i : j)] += dp[t][i] * dp[bit - t][j];
                    }
                }
            }
        } else continue;
    }
    rep(i, n) {
        cout << dp[mask - 1][i] << endl;
    }
    return 0;
}
0