結果

問題 No.753 最強王者決定戦
ユーザー betrue12betrue12
提出日時 2018-11-10 00:03:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 271 ms / 1,000 ms
コード長 3,087 bytes
コンパイル時間 2,067 ms
コンパイル使用メモリ 203,772 KB
実行使用メモリ 11,644 KB
最終ジャッジ日時 2023-08-13 12:17:27
合計ジャッジ時間 3,887 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 271 ms
11,644 KB
testcase_01 AC 270 ms
11,568 KB
testcase_02 AC 270 ms
11,632 KB
testcase_03 AC 269 ms
11,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

vector<int> choice42, choice84, choice168;
int64_t num[1<<16][16], ans[16];
int A[16][16];

int battle(int i, int j){
    if(i > j) swap(i, j);
    return (A[i][j] == 1 ? i : j);
}

int main(){
    for(int i=0; i<16; i++) for(int j=0; j<16; j++) cin >> A[i][j];

    for(int i=0; i<(1<<4); i++){
        int num = 0;
        for(int j=0; j<4; j++){
            if(nth_bit(i, j)) num++;
        }
        if(num == 2) choice42.push_back(i);
    }
    for(int i=0; i<(1<<8); i++){
        int num = 0;
        for(int j=0; j<8; j++){
            if(nth_bit(i, j)) num++;
        }
        if(num == 4) choice84.push_back(i);
    }

    for(int i=0; i<(1<<16); i++){
        vector<int> v;
        for(int j=0; j<16; j++){
            if(nth_bit(i, j)) v.push_back(j);
        }

        if(v.size() == 2){
            num[i][battle(v[0], v[1])]++;
        }

        if(v.size() == 4){
            for(auto bits : choice42){
                int b1 = 0, b2 = 0;
                vector<int> v1, v2;
                for(int j=0; j<4; j++){
                    if(nth_bit(bits, j)){
                        b1 += 1<<v[j];
                        v1.push_back(v[j]);
                    }else{
                        b2 += 1<<v[j];
                        v2.push_back(v[j]);
                    }
                }
                for(auto c1 : v1){
                    for(auto c2 : v2){
                        num[i][battle(c1, c2)] += num[b1][c1] * num[b2][c2];
                    }
                }
            }
        }

        if(v.size() == 8){
            choice168.push_back(i);
            for(auto bits : choice84){
                int b1 = 0, b2 = 0;
                vector<int> v1, v2;
                for(int j=0; j<8; j++){
                    if(nth_bit(bits, j)){
                        b1 += 1<<v[j];
                        v1.push_back(v[j]);
                    }else{
                        b2 += 1<<v[j];
                        v2.push_back(v[j]);
                    }
                }
                for(auto c1 : v1){
                    for(auto c2 : v2){
                        num[i][battle(c1, c2)] += num[b1][c1] * num[b2][c2];
                    }
                }
            }
        }

        if(v.size() == 16){
            for(auto bits : choice168){
                int b1 = 0, b2 = 0;
                vector<int> v1, v2;
                for(int j=0; j<16; j++){
                    if(nth_bit(bits, j)){
                        b1 += 1<<v[j];
                        v1.push_back(v[j]);
                    }else{
                        b2 += 1<<v[j];
                        v2.push_back(v[j]);
                    }
                }
                for(auto c1 : v1){
                    for(auto c2 : v2){
                        ans[battle(c1, c2)] += num[b1][c1] * num[b2][c2];
                    }
                }
            }
        }
    }

    for(int i=0; i<16; i++) cout << ans[i]*256 << endl;
    return 0;
}
0