結果
| 問題 | No.792 真理関数をつくろう | 
| コンテスト | |
| ユーザー |  kaito_tateyama | 
| 提出日時 | 2019-03-06 17:04:43 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 10 ms / 2,000 ms | 
| コード長 | 1,595 bytes | 
| コンパイル時間 | 872 ms | 
| コンパイル使用メモリ | 85,040 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-23 14:37:36 | 
| 合計ジャッジ時間 | 1,759 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 22 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define P(x) cout << (x) << "\n"
#define D(x) cerr << (x) << "\n"
#define fcout cout << fixed << setprecision(18)
using i64 = long long int; // 10^18
int n;
vector<bool> r;
vector<vector<bool>> q;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    REP(i, pow(2, n))
    {
        vector<bool> v;
        REP(j, n + 1)
        {
            if (j == n)
            {
                bool rr;
                cin >> rr;
                r.push_back(rr);
                continue;
            }
            bool vv;
            cin >> vv;
            v.push_back(vv);
        }
        q.push_back(v);
    }
    int flag = 0;
    for (auto rr : r)
    {
        flag += rr;
    }
    if (flag == 0)
    {
        cout << "A=⊥" << endl;
        return 0;
    }
    if (flag == pow(2, n))
    {
        cout << "A=⊤" << endl;
        return 0;
    }
    string s = "A=";
    for (int i = 0; i < (int)r.size(); ++i)
    {
        if (r[i] == 1)
        {
            string ss = "(";
            for (int j = 0; j < (int)q[i].size(); ++j)
            {
                ss += (q[i][j] == 0) ? "¬" : "";
                ss += "P_";
                ss += to_string(j + 1);
                if (j != (int)q[i].size() - 1)
                    ss += "∧";
            }
            ss += ")";
            s += ss;
            s += "∨";
        }
    }
    P(s.substr(0,(int)s.size()-3));
    return 0;
}
            
            
            
        