結果

問題 No.1937 Various Tournament
ユーザー shinchanshinchan
提出日時 2022-05-13 22:46:30
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 2,539 bytes
コンパイル時間 2,207 ms
使用メモリ 14,004 KB
最終ジャッジ日時 2023-02-21 16:04:12
合計ジャッジ時間 12,058 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
6,208 KB
testcase_01 AC 256 ms
13,928 KB
testcase_02 AC 256 ms
14,004 KB
testcase_03 AC 256 ms
13,804 KB
testcase_04 AC 255 ms
13,804 KB
testcase_05 AC 2 ms
6,272 KB
testcase_06 AC 256 ms
13,808 KB
testcase_07 AC 257 ms
13,880 KB
testcase_08 AC 1 ms
6,200 KB
testcase_09 AC 256 ms
13,920 KB
testcase_10 AC 1 ms
6,180 KB
testcase_11 AC 256 ms
13,908 KB
testcase_12 AC 254 ms
13,808 KB
testcase_13 AC 255 ms
13,880 KB
testcase_14 AC 256 ms
13,808 KB
testcase_15 AC 257 ms
13,804 KB
testcase_16 AC 256 ms
13,800 KB
testcase_17 AC 257 ms
13,812 KB
testcase_18 AC 256 ms
13,808 KB
testcase_19 AC 255 ms
13,804 KB
testcase_20 AC 2 ms
6,208 KB
testcase_21 AC 1 ms
6,272 KB
testcase_22 AC 256 ms
13,808 KB
testcase_23 AC 256 ms
13,960 KB
testcase_24 AC 255 ms
13,908 KB
testcase_25 AC 2 ms
6,196 KB
testcase_26 AC 255 ms
13,880 KB
testcase_27 AC 2 ms
6,276 KB
testcase_28 AC 256 ms
13,812 KB
testcase_29 AC 2 ms
6,276 KB
testcase_30 AC 256 ms
13,804 KB
testcase_31 AC 255 ms
13,812 KB
testcase_32 AC 255 ms
13,808 KB
testcase_33 AC 257 ms
13,964 KB
testcase_34 AC 256 ms
13,872 KB
testcase_35 AC 256 ms
13,832 KB
testcase_36 AC 257 ms
13,880 KB
testcase_37 AC 2 ms
6,196 KB
testcase_38 AC 2 ms
6,180 KB
testcase_39 AC 256 ms
13,900 KB
testcase_40 AC 1 ms
6,280 KB
testcase_41 AC 2 ms
6,252 KB
testcase_42 AC 256 ms
13,908 KB
testcase_43 AC 1 ms
6,280 KB
testcase_44 AC 1 ms
6,248 KB
testcase_45 AC 256 ms
13,900 KB
testcase_46 AC 2 ms
6,316 KB
testcase_47 AC 2 ms
6,248 KB
testcase_48 AC 1 ms
6,192 KB
testcase_49 AC 1 ms
6,168 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