#include <cstdio>
#include <string>
#include <iostream>
#include <set>
using namespace std;
int n, k, d, znak, wynik;
char c;
set<int> klauzule[1000001];
int maska;
int max_val;
int tab[24];
int stoi(const char *str){
int result = 0, i = 0;
while(str[i]!='\0'){
result *= 10;
result += (str[i] - '0');
i++;
}
return result;
}
int fnc(int x) {
// ~printf("IN:: %d\n", x);
int r = 0;
for(int i = 1; i <= k; ++i) {
for (set<int>::iterator it=klauzule[i].begin(); it!=klauzule[i].end(); ++it)
if (*it > 0 && (bool)(x&(1<<(*it - 1)))) {
r++;
break;
}
else if (*it < 0 && !(bool)(x&(1<<-(*it + 1)))){
r++; break;
}
}
return (r==k) ? 1 : 0;
}
int main() {
scanf("%d", &n);
if (n > 23) {
max_val = 1<<23;
}
else {
max_val = 1<<n;
}
znak = 1;
while(~scanf("%c", &c)){
if(c=='(') k++;
if(c=='x') {
scanf("%d", &d);
klauzule[k].emplace(znak * d);
znak = 1;
}
if(c=='~') {
znak = -1;
}
}
for (int i = 0; i < max_val; ++i) {
wynik += fnc(i);
}
printf("%d\n", wynik);
}
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | #include <cstdio> #include <string> #include <iostream> #include <set> using namespace std; int n, k, d, znak, wynik; char c; set<int> klauzule[1000001]; int maska; int max_val; int tab[24]; int stoi(const char *str){ int result = 0, i = 0; while(str[i]!='\0'){ result *= 10; result += (str[i] - '0'); i++; } return result; } int fnc(int x) { // ~printf("IN:: %d\n", x); int r = 0; for(int i = 1; i <= k; ++i) { for (set<int>::iterator it=klauzule[i].begin(); it!=klauzule[i].end(); ++it) if (*it > 0 && (bool)(x&(1<<(*it - 1)))) { r++; break; } else if (*it < 0 && !(bool)(x&(1<<-(*it + 1)))){ r++; break; } } return (r==k) ? 1 : 0; } int main() { scanf("%d", &n); if (n > 23) { max_val = 1<<23; } else { max_val = 1<<n; } znak = 1; while(~scanf("%c", &c)){ if(c=='(') k++; if(c=='x') { scanf("%d", &d); klauzule[k].emplace(znak * d); znak = 1; } if(c=='~') { znak = -1; } } for (int i = 0; i < max_val; ++i) { wynik += fnc(i); } printf("%d\n", wynik); } |
English