結果

問題 No.943 取り調べ
ユーザー face4face4
提出日時 2019-11-13 15:06:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 1,206 ms
コード長 1,180 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 65,984 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 03:26:45
合計ジャッジ時間 1,488 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,348 KB
testcase_04 AC 20 ms
4,348 KB
testcase_05 AC 17 ms
4,348 KB
testcase_06 AC 18 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 23 ms
4,348 KB
testcase_09 AC 6 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 6 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 7 ms
4,348 KB
testcase_23 AC 41 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int n;
    cin >> n;
    
    assert(1 <= n && n <= 18);

    int counton[n];
    for(int i = 0; i < n; i++){
        int tmp = 0;
        for(int j = 0; j < n; j++){
            char c; cin >> c;
            assert(c == '0' || c == '1');
            bool x = c == '1';
            if(x)   tmp += 1<<j;
        }
        counton[i] = tmp;
    }
    
    int a[n];
    for(int i = 0; i < n; i++)  cin >> a[i], assert(0 <= a[i] && a[i] <= 100000);

    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