結果

問題 No.943 取り調べ
ユーザー face4face4
提出日時 2019-11-14 22:32:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 250 ms / 1,206 ms
コード長 1,208 bytes
コンパイル時間 2,265 ms
コンパイル使用メモリ 77,576 KB
実行使用メモリ 57,724 KB
最終ジャッジ日時 2023-10-25 03:29:05
合計ジャッジ時間 7,217 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
57,472 KB
testcase_01 AC 130 ms
57,348 KB
testcase_02 AC 129 ms
57,496 KB
testcase_03 AC 127 ms
57,136 KB
testcase_04 AC 210 ms
57,672 KB
testcase_05 AC 229 ms
57,636 KB
testcase_06 AC 230 ms
57,368 KB
testcase_07 AC 130 ms
57,412 KB
testcase_08 AC 214 ms
57,564 KB
testcase_09 AC 181 ms
57,648 KB
testcase_10 AC 171 ms
57,560 KB
testcase_11 AC 162 ms
57,724 KB
testcase_12 AC 131 ms
57,536 KB
testcase_13 AC 142 ms
57,628 KB
testcase_14 AC 143 ms
57,440 KB
testcase_15 AC 137 ms
57,664 KB
testcase_16 AC 131 ms
57,496 KB
testcase_17 AC 184 ms
57,308 KB
testcase_18 AC 132 ms
57,564 KB
testcase_19 AC 140 ms
57,488 KB
testcase_20 AC 137 ms
57,596 KB
testcase_21 AC 133 ms
57,564 KB
testcase_22 AC 181 ms
57,496 KB
testcase_23 AC 250 ms
57,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] b = new int[n];
        for(int i = 0; i < n; i++){
            b[i] = 0;
            for(int j = 0; j < n; j++){
                int x = sc.nextInt();
                b[i] += (1<<j) * x;
            }
        }
        int[] a = new int[n];
        for(int i = 0; i < n; i++)  a[i] = sc.nextInt();
        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);
    }
}
0