結果

問題 No.792 真理関数をつくろう
コンテスト
ユーザー tsunabit
提出日時 2019-07-12 21:47:15
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 1,633 ms / 2,000 ms
コード長 1,004 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,510 ms
コンパイル使用メモリ 83,324 KB
実行使用メモリ 62,716 KB
最終ジャッジ日時 2026-05-13 06:42:29
合計ジャッジ時間 9,436 ms
ジャッジサーバーID
(参考情報)
judge3_1 / 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];
    	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 += "(";
    			for(int j = 0; j < n; j++) {
    				if(q[i][j] == 1) o += "P_" + (j+1) + "∧";
    				else o += "¬P_" + (j+1) + "∧";
        		}
    			o += ")";
    		}
    	}
    	if(c == 0) {
    		System.out.println("A=⊥");
    	}else if(c == (int)Math.pow(2, n)) {
    		System.out.println("A=⊤");
    	}else {
    		o = o.replaceAll("∧\\)\\(", "\\)∨\\(");
        	o = o.replaceAll("∧\\)", "\\)");
        	System.out.println(o);
    	}
    }
}
0