結果

問題 No.792 真理関数をつくろう
ユーザー tsunabittsunabit
提出日時 2019-07-12 21:56:14
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,358 bytes
コンパイル時間 7,208 ms
コンパイル使用メモリ 76,836 KB
実行使用メモリ 64,696 KB
最終ジャッジ日時 2023-08-12 00:25:19
合計ジャッジ時間 14,293 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 124 ms
55,816 KB
testcase_24 AC 140 ms
56,204 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

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 {
//    		o = o.replaceAll("∧\\)\\(", "\\)∨\\(");
    		sb.toString().replaceAll("∧\\)\\(", "\\)∨\\(");
//        	o = o.replaceAll("∧\\)", "\\)");
        	sb.toString().replaceAll("∧\\)", "\\)");
        	System.out.println(sb);
    	}
    }
}
0