結果

問題 No.792 真理関数をつくろう
ユーザー tsunabittsunabit
提出日時 2019-07-12 22:00:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 538 ms / 2,000 ms
コード長 1,136 bytes
コンパイル時間 6,428 ms
コンパイル使用メモリ 83,492 KB
実行使用メモリ 65,252 KB
最終ジャッジ日時 2023-08-12 00:34:58
合計ジャッジ時間 10,894 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 154 ms
55,588 KB
testcase_01 AC 266 ms
59,896 KB
testcase_02 AC 149 ms
55,792 KB
testcase_03 AC 307 ms
60,420 KB
testcase_04 AC 145 ms
55,964 KB
testcase_05 AC 302 ms
60,612 KB
testcase_06 AC 504 ms
61,864 KB
testcase_07 AC 239 ms
59,592 KB
testcase_08 AC 144 ms
56,016 KB
testcase_09 AC 153 ms
55,984 KB
testcase_10 AC 153 ms
55,836 KB
testcase_11 AC 147 ms
55,828 KB
testcase_12 AC 166 ms
56,064 KB
testcase_13 AC 146 ms
55,828 KB
testcase_14 AC 146 ms
56,308 KB
testcase_15 AC 208 ms
58,872 KB
testcase_16 AC 391 ms
60,696 KB
testcase_17 AC 197 ms
56,724 KB
testcase_18 AC 145 ms
55,564 KB
testcase_19 AC 145 ms
55,840 KB
testcase_20 AC 397 ms
60,932 KB
testcase_21 AC 538 ms
65,252 KB
testcase_22 AC 145 ms
55,996 KB
testcase_23 AC 127 ms
55,696 KB
testcase_24 AC 147 ms
55,972 KB
testcase_25 AC 153 ms
55,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No792 {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	StringBuilder sb = new StringBuilder();
    	sb.append("A=");
    	int[][] q = new int[(int)Math.pow(2, n)][n+1];
    	int c = 0;
    	// ∧∨¬⊥⊤
    	for(int i = 0; i < Math.pow(2, n); i++) {
    		for(int j = 0; j < n + 1; j++) {
    			q[i][j] = sc.nextInt();
    		}
    	}
    	
    	for(int i = 0; i < Math.pow(2, n); i++) {
    		if(q[i][n] == 1) {
    			c++;
    			sb.append("(");
    			for(int j = 0; j < n; j++) {
    				if(q[i][j] == 1)  sb.append("P_" + (j+1) + "∧");
    				else sb.append("¬P_" + (j+1) + "∧");
        		}
    			sb.append(")");
    			
    		}
    	}
    	if(c == 0) {
    		System.out.println("A=⊥");
    	}else if(c == (int)Math.pow(2, n)) {
    		System.out.println("A=⊤");
    	}else {
    		String str = "";
    		str = sb.toString().replaceAll("∧\\)\\(", "\\)∨\\(");
        	str = str.toString().replaceAll("∧\\)", "\\)");
        	System.out.println(str);
    	}
    }
}
0