#include #include #include using namespace std; struct ConvertILPToSat { vector< vector > A; vector b; ConvertILPToSat(int n, int m) : A(n, vector(m)), b(n) {} void printEquisatisfiableSatFormula() { int vars = A[0].size(); int eqs = A.size(); vector> clauses; // 5x1 + 2x2 + 3x3 ≤ 6 // vector that are no solutions : (1,1,1)=10, (1,1,0)=7, (1,0,1)=8 // corresponding clauses (!x || !y || !z), (!x || !y || z), (!x || y || !z) vector coefficients(vars, -1); for (int i = 0; i < eqs; i++) { vector equ = A[i]; // collect non 0 coefficients coefficients.clear(); for (int j = 0; j < vars; j++) { if (equ[j] != 0) coefficients.push_back(j); } vector clause; // for each bit combinaison for (int j = 0; j < (1< 0); int w = coefficients[k]; if (b) v += equ[w]; w += 1; clause.push_back(b ? -w: w); } if (v > b[i]) { clauses.push_back(clause); } } } int n = clauses.size(); if (n == 0) { cout << "1 1\n1 -1 0"<< endl; } else { cout << clauses.size() << " " << vars << endl; for (vector& c : clauses) { for (int v : c) { cout << v << " "; } cout << "0" << endl; } cout << endl; } } }; int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; ConvertILPToSat converter(n, m); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> converter.A[i][j]; } } for (int i = 0; i < n; i++) { cin >> converter.b[i]; } converter.printEquisatisfiableSatFormula(); return 0; }