結果
問題 |
No.943 取り調べ
|
ユーザー |
|
提出日時 | 2019-11-14 20:58:59 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 42 ms / 1,206 ms |
コード長 | 1,222 bytes |
コンパイル時間 | 503 ms |
コンパイル使用メモリ | 66,080 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-24 22:56:08 |
合計ジャッジ時間 | 1,337 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#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'); if(i == j) assert(c == '0'); 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; }