QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#457370 | #8770. Comparator | ucup-team3678 | AC ✓ | 122ms | 14504kb | C++14 | 2.7kb | 2024-06-29 11:04:45 | 2024-06-29 11:04:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
bool calc(string T) {
vector<bool> p; vector<int> q;
auto calc = [&](bool x, bool y, int z) -> bool {
if (z == 0) return x ^ y;
if (z == 1) return x | y;
if (z == 2) return x & y;
return x == y;
};
auto pop = [&]() {
if (q.back() == 4) p.back() = !p.back();
else p.end()[-2] = calc(p.back(), p.end()[-2], q.back()), p.pop_back();
q.pop_back();
};
reverse(T.begin(), T.end());
for (auto c : T) {
if (isdigit(c)) p.push_back(c ^ '0');
else if (c == ')') q.push_back(-2);
else {
int v = (c == '(' ? -1 : (c == '^' ? 0 : (c == '|' ? 1 : (c == '&' ? 2 : (c == '=' ? 3 : 4)))));
while (!q.empty() && q.back() > v) pop();
if (v == -1) q.pop_back(); else q.push_back(v);
}
}
while (!q.empty()) pop();
return p[0];
}
const int M = 10;
bool f[1 << M][1 << M];
bitset<1 << M> f1[1 << M], f2[1 << M];
signed main() {
int n, m; scanf("%d%d", &n, &m);
vector< pair< pair< pair<int, int>, pair<int, int> >, int> > tp;
map< pair< pair<int, int>, pair<int, int> >, int> M;
for (int i = 1; i <= n; ++i) {
int x, y; scanf("%d%d", &x, &y);
string S; cin >> S;
int z; scanf("%d", &z);
for (int j = 0; j < 2; ++j)
for (int k = 0; k < 2; ++k) {
if (M.count(make_pair(make_pair(x, j), make_pair(y, k)))) continue;
string T = S;
replace(T.begin(), T.end(), 'x', (char)(j + '0'));
replace(T.begin(), T.end(), 'y', (char)(k + '0'));
if (calc(T)) {
M[make_pair(make_pair(x, j), make_pair(y, k))] = 1;
tp.push_back(make_pair(make_pair(make_pair(x, j), make_pair(y, k)), z));
}
}
}
string T; cin >> T;
int res1 = 0, res2 = 0, res3 = 0;
for (int i = 0; i < 1 << m; ++i)
for (int j = 0; j < 1 << m; ++j) {
bool g = T[0] - '0';
for (auto [x, y] : tp) {
if (((i >> (x.first.first - 1)) & 1) == x.first.second && ((j >> (x.second.first - 1)) & 1) == x.second.second) {
g = y; break;
}
}
f[i][j] = g;
res1 += (i == j && f[i][j]);
if (f[i][j]) f1[i][j] = 1, f2[j][i] = 1;
}
for (int i = 0; i < 1 << m; ++i)
for (int j = 0; j < 1 << m; ++j) {
res2 += f[i][j] && f[j][i];
}
for (int i = 0; i < 1 << m; ++i)
for (int j = 0; j < 1 << m; ++j) if (!f[i][j]) {
res3 += (f1[i] & f2[j]).count();
}
printf("%d %d %d\n", res1, res2, res3);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
input:
3 2 1 1 (x=0)&(y=1) 1 1 1 (x=1)&(y=(x^x)) 0 2 2 (x=1)|(y=0) 0 1
output:
0 0 0
result:
ok single line: '0 0 0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
4 3 2 1 x=0&(y=1) 1 1 2 !x^!!y 0 2 3 ((x|1)=y)&1&1 1 3 1 !x&!x&!x 0 1
output:
3 25 52
result:
ok single line: '3 25 52'
Test #3:
score: 0
Accepted
time: 11ms
memory: 3900kb
input:
1413 3 1 3 0 0 3 3 !x 0 2 2 x=0 1 1 2 !y^0 1 2 3 (x^1) 0 3 2 ((!0)) 1 1 1 !!1=(y) 0 2 2 !(1^x)&y 1 3 2 (y)&1|!!1 0 3 1 !x=(y&y=y) 0 2 1 (((!1)^!x)) 1 2 3 !0=(0&y)=1&y 0 1 2 ((((!0)))|!1) 0 3 1 !(y=!1=x|(!x)) 0 1 1 ((((y=!y)))&!0) 0 2 3 ((y=1)^!1^!!1|0) 1 2 3 1|(!x)&!x|1|(x=1) 1 2 3 !0^!!!!y&0=(!1&!0...
output:
4 16 0
result:
ok single line: '4 16 0'
Test #4:
score: 0
Accepted
time: 66ms
memory: 5128kb
input:
181737 10 5 2 1 1 1 10 !1=!x 0 10 1 (1^x) 0 2 4 !1 1 10 8 y=(!1)^1 1 6 2 !((x&!x)) 1 1 10 !!((!x)|x) 1 7 10 (((0))) 0 7 3 !(1)^!x 0 10 4 (!1)&x 0 7 7 !y&!0 1 8 8 !1=(x)|1^1 1 2 6 ((!!!x)) 0 7 2 1 1 2 2 y=1=0 0 6 3 (!0) 0 6 4 0 0 1 1 (!1) 1 1 8 y 1 3 5 !x|!x^!1 0 4 7 (!0) 0 3 4 !1&1&!1|!0 1 2 7 ((0|1...
output:
1024 1048576 0
result:
ok single line: '1024 1048576 0'
Test #5:
score: 0
Accepted
time: 37ms
memory: 14504kb
input:
1 3 1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...
output:
4 16 0
result:
ok single line: '4 16 0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 4076kb
input:
1 1 1 1 x^y|1 0 1
output:
1 1 0
result:
ok single line: '1 1 0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 4076kb
input:
1 1 1 1 x&y|1 0 1
output:
0 0 0
result:
ok single line: '0 0 0'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
1 1 1 1 x=y|1 0 1
output:
0 0 0
result:
ok single line: '0 0 0'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
2 2 1 2 !x&!y 1 1 1 !x&y 0 1
output:
4 12 2
result:
ok single line: '4 12 2'
Test #10:
score: 0
Accepted
time: 62ms
memory: 5044kb
input:
2 10 9 8 ((((!((!x=1))^(!1&(x|x|!y))&((!y&!x=(x=y)))&!((((x=1))&(0=(y))^(!!(!!x^1=x)&(x)^y&1=!x&1=(((!0^(1)^1))^!(((((y))|x|!y))))^!!0=!y&(0)|(y=x&!y&y=x)))=((((!!y&!!0|!0^!0)=!x))))^0&(((!1=!(!x)))|(((((x=1|!y|y)=(!1^1^0^(0)))=!0^1)))=(!(!1^(((((!1)^!x^0))))=(1)^((((y=((x))|(0)|(!1^1)))|(!!!y))=((!...
output:
0 0 0
result:
ok single line: '0 0 0'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
4 3 1 1 !!!!!!x 0 2 1 !!y 1 1 2 !!!!!x 1 2 2 !!!x 0 1
output:
4 16 0
result:
ok single line: '4 16 0'
Test #12:
score: 0
Accepted
time: 3ms
memory: 4704kb
input:
1 1 1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
output:
1 1 0
result:
ok single line: '1 1 0'
Test #13:
score: 0
Accepted
time: 122ms
memory: 5092kb
input:
200000 10 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10...
output:
512 262144 134217728
result:
ok single line: '512 262144 134217728'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
10 3 3 1 (!x) 1 3 2 !1&x&1&!y 1 2 1 ((x)&y) 1 1 3 0 0 2 2 !1&0=y&0 1 3 3 (!y)^y 1 2 1 0|((!y)) 0 3 2 x 0 2 2 (y|1^x) 0 2 1 ((!0)|y) 0 1
output:
8 64 0
result:
ok single line: '8 64 0'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
0 3 1
output:
8 64 0
result:
ok single line: '8 64 0'