結果

問題 No.792 真理関数をつくろう
ユーザー aaaaaaiu
提出日時 2019-08-01 15:20:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 874 bytes
コンパイル時間 1,888 ms
コンパイル使用メモリ 193,012 KB
最終ジャッジ日時 2025-01-07 10:26:40
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int q[1<<n][n];
    int r[1<<n];
    int rsum = 0;
    for (int i = 0; i < 1<<n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> q[i][j];
        }
        cin >> r[i];
        rsum += r[i];
    }
    cout << "A=";
    if (rsum == 0) cout << "⊥";
    else if (rsum == 1<<n) cout << "⊤";
    else {
        bool V = false;
        for (int i = 0; i < 1<<n; i++) {
            if (!r[i]) continue;
            if (V) cout << "∨";
            cout << '(';
            for (int j = 0; j < n; j++) {
                if (j != 0) cout << "∧";
                if (q[i][j] == 0) cout << "¬";
                cout << "P_" << j+1;
            }
            cout << ')';
            if (!V) V = true;
        }
    }
    cout << endl;
    return 0;
}
0