結果
問題 | No.943 取り調べ |
ユーザー | face4 |
提出日時 | 2019-11-14 22:39:15 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 182 ms / 1,206 ms |
コード長 | 1,766 bytes |
コンパイル時間 | 2,472 ms |
コンパイル使用メモリ | 77,904 KB |
実行使用メモリ | 55,716 KB |
最終ジャッジ日時 | 2023-10-25 03:29:36 |
合計ジャッジ時間 | 5,201 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
52,176 KB |
testcase_01 | AC | 56 ms
53,272 KB |
testcase_02 | AC | 55 ms
53,264 KB |
testcase_03 | AC | 55 ms
53,268 KB |
testcase_04 | AC | 138 ms
55,716 KB |
testcase_05 | AC | 151 ms
55,532 KB |
testcase_06 | AC | 150 ms
55,496 KB |
testcase_07 | AC | 54 ms
53,192 KB |
testcase_08 | AC | 140 ms
55,552 KB |
testcase_09 | AC | 115 ms
55,620 KB |
testcase_10 | AC | 101 ms
55,540 KB |
testcase_11 | AC | 95 ms
55,520 KB |
testcase_12 | AC | 55 ms
52,216 KB |
testcase_13 | AC | 56 ms
53,272 KB |
testcase_14 | AC | 58 ms
53,272 KB |
testcase_15 | AC | 55 ms
53,260 KB |
testcase_16 | AC | 57 ms
53,256 KB |
testcase_17 | AC | 88 ms
55,592 KB |
testcase_18 | AC | 56 ms
53,268 KB |
testcase_19 | AC | 55 ms
53,272 KB |
testcase_20 | AC | 56 ms
53,252 KB |
testcase_21 | AC | 54 ms
53,264 KB |
testcase_22 | AC | 100 ms
55,612 KB |
testcase_23 | AC | 182 ms
55,416 KB |
ソースコード
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); } }