結果

問題 No.1937 Various Tournament
ユーザー tatyamtatyam
提出日時 2022-04-08 19:19:53
言語 C++23(draft)
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,346 bytes
コンパイル時間 3,109 ms
使用メモリ 12,880 KB
最終ジャッジ日時 2023-01-05 01:20:39
合計ジャッジ時間 6,499 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
6,952 KB
testcase_01 AC 23 ms
12,096 KB
testcase_02 AC 31 ms
12,828 KB
testcase_03 AC 32 ms
12,732 KB
testcase_04 AC 30 ms
12,804 KB
testcase_05 AC 1 ms
4,900 KB
testcase_06 AC 33 ms
12,780 KB
testcase_07 AC 32 ms
12,832 KB
testcase_08 AC 1 ms
6,952 KB
testcase_09 AC 33 ms
12,880 KB
testcase_10 AC 1 ms
4,900 KB
testcase_11 AC 29 ms
12,204 KB
testcase_12 AC 32 ms
12,724 KB
testcase_13 AC 29 ms
12,804 KB
testcase_14 AC 32 ms
12,776 KB
testcase_15 AC 32 ms
12,800 KB
testcase_16 AC 31 ms
12,732 KB
testcase_17 AC 31 ms
12,768 KB
testcase_18 AC 32 ms
12,780 KB
testcase_19 AC 31 ms
12,828 KB
testcase_20 AC 2 ms
6,948 KB
testcase_21 AC 1 ms
4,900 KB
testcase_22 AC 31 ms
12,728 KB
testcase_23 AC 32 ms
12,732 KB
testcase_24 AC 32 ms
12,800 KB
testcase_25 AC 1 ms
4,904 KB
testcase_26 AC 32 ms
12,728 KB
testcase_27 AC 1 ms
4,900 KB
testcase_28 AC 29 ms
12,268 KB
testcase_29 AC 2 ms
4,900 KB
testcase_30 AC 32 ms
12,804 KB
testcase_31 AC 31 ms
12,796 KB
testcase_32 AC 33 ms
12,796 KB
testcase_33 AC 32 ms
12,800 KB
testcase_34 AC 32 ms
12,780 KB
testcase_35 AC 32 ms
12,800 KB
testcase_36 AC 33 ms
12,852 KB
testcase_37 AC 1 ms
4,904 KB
testcase_38 AC 1 ms
4,900 KB
testcase_39 AC 31 ms
12,800 KB
testcase_40 AC 1 ms
4,904 KB
testcase_41 AC 2 ms
6,948 KB
testcase_42 AC 33 ms
12,828 KB
testcase_43 AC 2 ms
4,904 KB
testcase_44 AC 1 ms
4,908 KB
testcase_45 AC 33 ms
12,848 KB
testcase_46 AC 2 ms
6,952 KB
testcase_47 AC 1 ms
4,900 KB
testcase_48 AC 1 ms
4,904 KB
testcase_49 AC 1 ms
4,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using u32 = uint32_t;
using ll = long long;


int main(){
    int N;
    cin >> N;
    vector S(N, vector<int>(N));
    for(auto& s : S) for(int& i : s) cin >> i;
    // dp[winner][bit] = #arrangement
    vector dp(N, vector<ll>(1 << N));
    vector<pair<int, u32>> A;
    for(int i = 0; i < N; i++){
        dp[i][1 << i] = 1;
        A.emplace_back(i, 1 << i);
    }
    for(int i = 2; i < N; i <<= 1){
        vector<pair<int, u32>> B;
        for(int i = 0; i < A.size(); i++) for(int j = i + 1; j < A.size(); j++){
            auto [a, bit1] = A[i];
            auto [b, bit2] = A[j];
            if(bit1 & bit2) continue;
            auto add = [&](int a, u32 b, ll x){
                if(dp[a][b] == 0) B.emplace_back(a, b);
                dp[a][b] += x;
            };
            add(S[a][b] ? a : b, bit1 | bit2, dp[a][bit1] * dp[b][bit2] * 2);
        }
        A = move(B);
    }
    const int mask = (1 << N) - 1;
    for(int bit = 0; bit < 1 << (N - 1); bit++) if(__builtin_popcount(bit) == N / 2){
        for(int i = 0; i < N; i++) if(bit & 1 << i){
            for(int j = 0; j < N; j++) if(~bit & 1 << j){
                dp[S[i][j] ? i : j].back() += dp[i][bit] * dp[j][~bit & mask] * 2;
            }
        }
    }
    for(int i = 0; i < N; i++) cout << dp[i].back() << '\n';
}
0