結果

問題 No.1937 Various Tournament
ユーザー 👑 tatyamtatyam
提出日時 2022-04-08 19:19:53
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,346 bytes
コンパイル時間 3,542 ms
コンパイル使用メモリ 257,368 KB
実行使用メモリ 13,060 KB
最終ジャッジ日時 2023-08-18 23:13:53
合計ジャッジ時間 7,126 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 24 ms
11,928 KB
testcase_02 AC 31 ms
12,744 KB
testcase_03 AC 32 ms
12,872 KB
testcase_04 AC 30 ms
12,828 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 31 ms
12,720 KB
testcase_07 AC 32 ms
12,828 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 34 ms
12,832 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 30 ms
12,268 KB
testcase_12 AC 33 ms
12,868 KB
testcase_13 AC 30 ms
12,880 KB
testcase_14 AC 32 ms
13,060 KB
testcase_15 AC 32 ms
12,756 KB
testcase_16 AC 32 ms
12,892 KB
testcase_17 AC 34 ms
12,868 KB
testcase_18 AC 33 ms
12,740 KB
testcase_19 AC 31 ms
12,664 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 31 ms
12,880 KB
testcase_23 AC 31 ms
12,700 KB
testcase_24 AC 30 ms
12,672 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 30 ms
13,012 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 28 ms
12,240 KB
testcase_29 AC 2 ms
4,388 KB
testcase_30 AC 31 ms
12,828 KB
testcase_31 AC 30 ms
12,664 KB
testcase_32 AC 33 ms
12,828 KB
testcase_33 AC 32 ms
12,712 KB
testcase_34 AC 32 ms
12,904 KB
testcase_35 AC 32 ms
12,808 KB
testcase_36 AC 33 ms
12,732 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 32 ms
12,900 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 35 ms
12,872 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 1 ms
4,384 KB
testcase_45 AC 33 ms
13,056 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,376 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