結果

問題 No.792 真理関数をつくろう
ユーザー msm1993
提出日時 2019-03-07 18:34:35
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 906 bytes
コンパイル時間 1,369 ms
コンパイル使用メモリ 162,980 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-23 14:52:08
合計ジャッジ時間 2,227 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int n;
    cin >> n;
    bool isTop = true;
    bool isBottom = true;
    string ans = "A=";
    int loop = pow(2, n);

    bool existPre = false;
    for(int i=0; i<loop; i++){
        vector<int> v(n+1);
        for(int j=0; j<=n; j++){
            cin >> v[j];
        }
        if(v[n] == 1){
            isBottom = false;
            if(existPre) ans += "∨";
            existPre = true;
            ans += "(";
            for(int j=0; j<n; j++){
                if(v[j] == 1) ans += ("P_" + to_string(j+1));
                else if(v[j] == 0) ans += ("¬P_" + to_string(j+1));
                if(j != n-1) ans += "∧";
            }
            ans += ")";
        }
        else isTop = false;
    }
    if(isTop) cout << "A=⊤" << endl;
    else if(isBottom) cout << "A=⊥" << endl;
    else cout << ans << endl;

    return 0;
}
0