結果

問題 No.792 真理関数をつくろう
ユーザー tsunabittsunabit
提出日時 2019-07-12 21:59:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 535 ms / 2,000 ms
コード長 1,411 bytes
コンパイル時間 6,982 ms
コンパイル使用メモリ 78,900 KB
実行使用メモリ 64,796 KB
最終ジャッジ日時 2023-08-12 00:33:58
合計ジャッジ時間 13,179 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
56,140 KB
testcase_01 AC 265 ms
60,732 KB
testcase_02 AC 146 ms
55,724 KB
testcase_03 AC 306 ms
60,592 KB
testcase_04 AC 143 ms
56,020 KB
testcase_05 AC 306 ms
60,660 KB
testcase_06 AC 483 ms
61,888 KB
testcase_07 AC 238 ms
59,148 KB
testcase_08 AC 143 ms
55,680 KB
testcase_09 AC 153 ms
55,760 KB
testcase_10 AC 153 ms
55,748 KB
testcase_11 AC 147 ms
56,084 KB
testcase_12 AC 163 ms
55,924 KB
testcase_13 AC 145 ms
56,372 KB
testcase_14 AC 146 ms
56,024 KB
testcase_15 AC 216 ms
56,580 KB
testcase_16 AC 394 ms
62,712 KB
testcase_17 AC 179 ms
56,680 KB
testcase_18 AC 145 ms
55,780 KB
testcase_19 AC 145 ms
55,752 KB
testcase_20 AC 423 ms
60,464 KB
testcase_21 AC 535 ms
64,796 KB
testcase_22 AC 146 ms
56,156 KB
testcase_23 AC 127 ms
55,880 KB
testcase_24 AC 143 ms
55,812 KB
testcase_25 AC 152 ms
55,828 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();
//    	String o = "A=";
    	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++;
//    			o += "(";
    			sb.append("(");
    			for(int j = 0; j < n; j++) {
//    				if(q[i][j] == 1)  o += "P_" + (j+1) + "∧";
    				if(q[i][j] == 1)  sb.append("P_" + (j+1) + "∧");
//    				else o += "¬P_" + (j+1) + "∧";
    				else sb.append("¬P_" + (j+1) + "∧");
        		}
//    			o += ")";
    			sb.append(")");
    			
    		}
    	}
    	if(c == 0) {
    		System.out.println("A=⊥");
    	}else if(c == (int)Math.pow(2, n)) {
    		System.out.println("A=⊤");
    	}else {
    		String str = "";
//    		        o = o.replaceAll("∧\\)\\(", "\\)∨\\(");
    		str = sb.toString().replaceAll("∧\\)\\(", "\\)∨\\(");
//        	        o = o.replaceAll("∧\\)", "\\)");
        	str = str.toString().replaceAll("∧\\)", "\\)");
        	System.out.println(str);
    	}
    }
}
0