結果
問題 |
No.943 取り調べ
|
ユーザー |
|
提出日時 | 2019-11-14 22:39:15 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 192 ms / 1,206 ms |
コード長 | 1,766 bytes |
コンパイル時間 | 2,283 ms |
コンパイル使用メモリ | 77,520 KB |
実行使用メモリ | 52,340 KB |
最終ジャッジ日時 | 2024-09-24 22:58:34 |
合計ジャッジ時間 | 4,695 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
import java.io.InputStreamReader; import java.io.IOException; import java.io.BufferedReader; public class Main{ public static void main(String args[]) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] b = new int[n]; for(int i = 0; i < n; i++){ b[i] = 0; String line = br.readLine(); if(line.charAt(line.length()-1) == ' ') System.exit(1); String[] arr = line.split(" "); if(arr.length != n) System.exit(1); for(int j = 0; j < n; j++){ int x = Integer.parseInt(arr[j]); b[i] += (1<<j) * x; } } int[] a = new int[n]; String line = br.readLine(); if(line.charAt(line.length()-1) == ' ') System.exit(1); String[] arr = line.split(" "); if(arr.length != n) System.exit(1); for(int i = 0; i < n; i++) a[i] = Integer.parseInt(arr[i]); int ans = 1<<30; for(int i = 0; i < 1<<n; i++){ int score = 0; for(int j = 0; j < n; j++){ if(((i>>j)&1) == 1) score += a[j]; } // 高速化出来る(しなくてもよい) // if(score >= ans) continue; int lie = i, confess = 0, k = -1; while(++k < n){ if(((confess>>k)&1) == 1) continue; if((lie&b[k]) == b[k]){ confess |= 1<<k; lie |= 1<<k; k = -1; } } if(confess == (1<<n)-1) ans = Math.min(ans, score); } System.out.println(ans); } }