結果

問題 No.943 取り調べ
ユーザー face4face4
提出日時 2019-11-13 12:32:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 1,206 ms
コード長 1,020 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 65,872 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 03:26:39
合計ジャッジ時間 2,182 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 25 ms
4,348 KB
testcase_05 AC 21 ms
4,348 KB
testcase_06 AC 20 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 29 ms
4,348 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 6 ms
4,348 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 7 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 8 ms
4,348 KB
testcase_23 AC 46 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<numeric>
using namespace std;

int main(){
    int n;
    cin >> n;
    
    int counton[n];
    for(int i = 0; i < n; i++){
        int tmp = 0;
        for(int j = 0; j < n; j++){
            bool x; cin >> x;
            if(x)   tmp += 1<<j;
        }
        counton[i] = tmp;
    }
    
    int a[n];
    for(int i = 0; i < n; i++)  cin >> a[i];

    int ans = accumulate(a, a+n, 0);
    for(int i = 0; i < 1<<n; i++){
        int score = 0;
        for(int j = 0; j < n; j++){
            if((i>>j)&1)  score += a[j];
        }

        // 枝刈り出来る(しなくてもよい)
        if(score >= ans) continue;

        int lie = i, confess = 0, k = -1;
        while(++k < n){
            if((confess>>k)&1)  continue;
            if((lie&counton[k]) == counton[k]){
                confess |= 1<<k;
                lie |= 1<<k;
                k = -1;
            }
        }
        
        if(confess == (1<<n)-1) ans = score;
    }

    cout << ans << endl;

    return 0;
}
0