結果

問題 No.753 最強王者決定戦
ユーザー mugen_1337mugen_1337
提出日時 2021-03-30 09:41:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 500 ms / 1,000 ms
コード長 2,421 bytes
コンパイル時間 2,291 ms
コンパイル使用メモリ 212,188 KB
実行使用メモリ 11,756 KB
最終ジャッジ日時 2023-08-20 06:19:59
合計ジャッジ時間 5,285 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 498 ms
11,748 KB
testcase_01 AC 500 ms
11,756 KB
testcase_02 AC 491 ms
11,680 KB
testcase_03 AC 497 ms
11,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ALL(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 998244353
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

inline vector<int> enumerate_subset(int bit,bool include_bit_empty=false){
    vector<int> ret;
    int subset=(bit-1)&bit;
    do{
        ret.push_back(subset);
        subset=(subset-1)&bit;
    }while(subset!=0);
    if(include_bit_empty){
        ret.push_back(0);
        if(0!=bit) ret.push_back(bit);
    }
    return ret;
}

const int n=16;

signed main(){
    vector<vector<int>> a(n,vector<int>(n));
    cin>>a;

    rep(i,n)rep(j,i) a[i][j]=a[j][i]*(-1);
    
    auto f=[&](int i,int j){
        if(a[i][j]>0) return i;
        return j;
    };

    vector<vector<ll>> dp(n,vector<ll>(1<<n,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)if(i!=j){
            int k=f(i,j);
            dp[k][(1<<i)+(1<<j)]=2;
        }
    }

    for(int bit=0;bit<(1<<n);bit++){
        int popcount=__builtin_popcount(bit);
        if(popcount>=4 and popcount%2==0){
            for(auto &l:enumerate_subset(bit)){
                if(__builtin_popcount(l)==popcount/2){
                    int r=(bit^l);

                    for(int i=0;i<n;i++)if((l>>i)&1 and dp[i][l]>0){
                        for(int j=0;j<n;j++)if((r>>j)&1){
                            int k=f(i,j);
                            dp[k][bit]+=dp[i][l]*dp[j][r];
                        }
                    }
                }
            }

        }
    }
    rep(i,n){
        cout<<dp[i][(1<<n)-1]<<endl;
    }
    return 0;
}
0