結果

問題 No.792 真理関数をつくろう
コンテスト
ユーザー tsunabit
提出日時 2019-07-11 23:37:31
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 1,685 ms / 2,000 ms
コード長 1,125 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,608 ms
コンパイル使用メモリ 84,096 KB
実行使用メモリ 60,308 KB
最終ジャッジ日時 2026-05-08 22:27:12
合計ジャッジ時間 11,223 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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=";
    	int[][] q = new int[(int)Math.pow(2, n)][n+1];
    	boolean f0 = false, f1 = false;
    	// ∧∨¬⊥⊤
    	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] == 0) f0 = true;
    			else f1 = true;
    	}
    	if(f0 && !f1) {
    		System.out.println("A=⊥");
    		return;
    	}else if(!f0 && f1) {
    		System.out.println("A=⊤");
    		return;
    	}
    	
    	for(int i = 0; i < Math.pow(2, n); i++) {
    		if(q[i][n] == 1) {
    			o += "(";
    			for(int j = 0; j < n; j++) {
    				if(q[i][j] == 1) o += "P_" + (j+1) + "∧";
    				else o += "¬P_" + (j+1) + "∧";
        		}
    			o += ")";
    		}
    	}
    	o = o.replaceAll("∧\\)\\(", "\\)∨\\(");
    	o = o.replaceAll("∧\\)", "\\)");
    	System.out.println(o);
    }
}
0