結果

問題 No.792 真理関数をつくろう
ユーザー tentententen
提出日時 2021-02-10 13:33:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 1,463 bytes
コンパイル時間 2,177 ms
コンパイル使用メモリ 74,676 KB
実行使用メモリ 59,912 KB
最終ジャッジ日時 2023-09-22 07:37:00
合計ジャッジ時間 7,823 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,880 KB
testcase_01 AC 184 ms
55,640 KB
testcase_02 AC 126 ms
55,740 KB
testcase_03 AC 203 ms
58,556 KB
testcase_04 AC 125 ms
55,956 KB
testcase_05 AC 196 ms
55,960 KB
testcase_06 AC 261 ms
59,912 KB
testcase_07 AC 162 ms
55,824 KB
testcase_08 AC 128 ms
55,820 KB
testcase_09 AC 125 ms
55,544 KB
testcase_10 AC 127 ms
55,396 KB
testcase_11 AC 127 ms
55,780 KB
testcase_12 AC 129 ms
56,000 KB
testcase_13 AC 127 ms
55,944 KB
testcase_14 AC 129 ms
55,792 KB
testcase_15 AC 151 ms
55,896 KB
testcase_16 AC 225 ms
58,924 KB
testcase_17 AC 136 ms
55,796 KB
testcase_18 AC 129 ms
55,708 KB
testcase_19 AC 130 ms
55,768 KB
testcase_20 AC 227 ms
59,152 KB
testcase_21 AC 283 ms
59,168 KB
testcase_22 AC 130 ms
55,436 KB
testcase_23 AC 130 ms
55,632 KB
testcase_24 AC 126 ms
55,336 KB
testcase_25 AC 129 ms
55,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        StringBuilder sb = new StringBuilder();
        int trueCount = 0;
        int falseCount = 0;
        sb.append("A=");
        boolean isFirst = true;
        for (int i = 0; i < (1 << n); i++) {
            char[] line = sc.nextLine().toCharArray();
            boolean[] tfs = new boolean[n + 1];
            for (int j = 0; j < line.length; j += 2) {
                tfs[j / 2] = (line[j] == '1');
            }
            if (tfs[n]) {
                trueCount++;
                if (!isFirst) {
                    sb.append("∨");
                }
                isFirst = false;
                sb.append("(");
                for (int j = 0; j < n; j++) {
                    if (j > 0) {
                        sb.append("∧");
                    }
                    if (!tfs[j]) {
                        sb.append("¬");
                    }
                    sb.append("P_").append(j + 1);
                }
                sb.append(")");
            } else {
                falseCount++;
            }
        }
        if (trueCount == (1 << n)) {
            System.out.println("A=⊤");
        } else if (falseCount == (1 << n)) {
            System.out.println("A=⊥");
        } else {
            System.out.println(sb);
        }
    }
}
0