結果
| 問題 | No.792 真理関数をつくろう | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-07-12 21:59:56 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 550 ms / 2,000 ms | 
| コード長 | 1,411 bytes | 
| コンパイル時間 | 3,847 ms | 
| コンパイル使用メモリ | 79,500 KB | 
| 実行使用メモリ | 51,760 KB | 
| 最終ジャッジ日時 | 2024-11-18 20:19:04 | 
| 合計ジャッジ時間 | 9,865 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 22 | 
ソースコード
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);
    	}
    }
}
            
            
            
        