#include <bits/stdc++.h> using namespace std; vector<vector<int>> V; int S[1000001]; int cur; int sum; bool evall(const vector<int> &v) { for (const auto &x : v) { if ((x > 0) == (((cur >> (S[abs(x)]-1)) & 1) == 1)) { return true; } } return false; } bool eval() { for (const auto &v : V) { if (!evall(v)) return false; } return true; } int main() { int n; scanf("%d", &n); int c; V.resize(1); bool neg = false; int p = 0, pp = 1; while ((c=getchar_unlocked()) != EOF) { if (c == ')' || c == 'v') { V.back().emplace_back((neg?-1:1)*p); if (!S[p]) S[p]=pp++; neg=false; p=0; } else if (c == '^') { V.resize(V.size()+1); } else if (c >= '0' && c <= '9') { p = p * 10 + c - '0'; } else if (c == '~') neg = true; } pp--; for (;cur < (1 << pp); cur++) { if (eval()) sum++; } printf("%d\n", sum % (1000000007)); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include <bits/stdc++.h> using namespace std; vector<vector<int>> V; int S[1000001]; int cur; int sum; bool evall(const vector<int> &v) { for (const auto &x : v) { if ((x > 0) == (((cur >> (S[abs(x)]-1)) & 1) == 1)) { return true; } } return false; } bool eval() { for (const auto &v : V) { if (!evall(v)) return false; } return true; } int main() { int n; scanf("%d", &n); int c; V.resize(1); bool neg = false; int p = 0, pp = 1; while ((c=getchar_unlocked()) != EOF) { if (c == ')' || c == 'v') { V.back().emplace_back((neg?-1:1)*p); if (!S[p]) S[p]=pp++; neg=false; p=0; } else if (c == '^') { V.resize(V.size()+1); } else if (c >= '0' && c <= '9') { p = p * 10 + c - '0'; } else if (c == '~') neg = true; } pp--; for (;cur < (1 << pp); cur++) { if (eval()) sum++; } printf("%d\n", sum % (1000000007)); } |