結果

問題 No.792 真理関数をつくろう
ユーザー k
提出日時 2020-06-26 00:02:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 921 bytes
コンパイル時間 2,895 ms
コンパイル使用メモリ 198,196 KB
最終ジャッジ日時 2025-01-11 10:28:16
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  vector<vector<int> > Q;
  vector<int> R;

  REP (i, 1<<n) {
    vector<int> tmp(n);
    REP (j, n) cin >> tmp[j];
    Q.push_back(tmp);
    int r;
    cin >> r;
    R.push_back(r);
  }
  
  int sum = 0;
  REP (i, 1<<n) sum += R[i];
  if (sum == 0) {
    cout << "A=⊥" << endl;
  } else if (sum == (1<<n)) {
    cout << "A=⊤" << endl;
  } else {
    cout << "A=";
    bool fst = true;
    REP(i, 1<<n) {
      if (R[i]) {
        if (!fst)
          cout << "∨";
        fst = false;
        cout << "(";
        REP (j, n) {
          if (j)
            cout << "∧";
          if (!Q[i][j])
            cout << "¬";
          cout << "P_" << (j+1);
        }
        cout << ")";
      }
    }
    cout << endl;
  }
  
  return 0;
}
0