QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#454292 | #8770. Comparator | ucup-team173# | WA | 209ms | 158368kb | C++20 | 4.2kb | 2024-06-24 18:39:07 | 2024-06-24 18:39:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
int pos, len, lastVal;
string str;
int tot = 0, ty[MAXN], ch[MAXN][2];
int buildExpress() {
vector<int> tt, op;
while (pos < len) {
if (str[pos] == '(') {
pos++;
tt.push_back(buildExpress());
} else if (str[pos] == '!') {
pos++;
int g = ++tot;
ty[g] = -1, ch[g][0] = buildExpress();
tt.push_back(g);
} else if (str[pos] == 'x') {
ty[++tot] = 2, tt.push_back(tot), pos++;
} else if (str[pos] == 'y') {
ty[++tot] = 3, tt.push_back(tot), pos++;
} else if (str[pos] == '0') {
ty[++tot] = 0, tt.push_back(tot), pos++;
} else if (str[pos] == '1') {
ty[++tot] = 1, tt.push_back(tot), pos++;
} else if (str[pos] == '&') {
op.push_back(-2), pos++;
} else if (str[pos] == '|') {
op.push_back(-3), pos++;
} else if (str[pos] == '^') {
op.push_back(-4), pos++;
} else if (str[pos] == '=') {
op.push_back(-5), pos++;
} else if(str[pos] == ')') {
pos++;
break;
}
}
int last = tt[0];
for (int i = 1; i < tt.size(); i++) {
int t = ++tot;
ty[t] = op[i - 1];
ch[t][0] = last;
ch[t][1] = tt[i];
last = t;
}
return last;
}
int dfs(int x, int val_x, int val_y) {
if (ty[x] == 2) return val_x;
if (ty[x] == 3) return val_y;
if (ty[x] >= 0) return ty[x];
if (ty[x] == -1) return !dfs(ch[x][0], val_x, val_y);
if (ty[x] == -2) {
return dfs(ch[x][0], val_x, val_y) & dfs(ch[x][1], val_x, val_y);
}
if (ty[x] == -3) {
return dfs(ch[x][0], val_x, val_y) | dfs(ch[x][1], val_x, val_y);
}
if (ty[x] == -4) {
return dfs(ch[x][0], val_x, val_y) ^ dfs(ch[x][1], val_x, val_y);
}
if (ty[x] == -5) {
return dfs(ch[x][0], val_x, val_y) == dfs(ch[x][1], val_x, val_y);
}
}
int calc(string s) {
pos = 0, str = s, len = str.size();
tot = 0;
int rt = buildExpress(), sta = 0;
for (int x = 0; x <= 1; x++) {
for (int y = 0; y <= 1; y++) {
if (dfs(rt, x, y)) sta |= 1 << (x << 1 | y);
}
}
return sta;
}
struct Node {
int a, b, sta, val;
};
vector<Node> f;
map<pair<pair<int, int>, int>, bool> tt;
bitset<1024> S[10][4], full;
bitset<1024> getLimit(int A) {
bitset<1024> now = full, lim = 0;
for (auto node : f) {
int a = node.a, b = node.b, sta = node.sta, val = node.val;
int x = A >> a & 1, pp = 0;
for (int y = 0; y <= 1; y++) {
if (sta >> (x << 1 | y) & 1) {
pp |= 1 << y;
}
}
if (val == 1) {
lim |= now & S[b][pp];
}
now &= S[b][pp ^ 3];
}
if (lastVal) {
lim |= now;
}
return lim;
}
bitset<1024> outEdge[1024];
void solve() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
int a, b, val;
string s;
cin >> a >> b >> s >> val;
a--, b--;
int t = calc(s);
if (tt.find(make_pair(make_pair(a, b), t)) == tt.end()) {
tt[make_pair(make_pair(a, b), t)] = 1;
f.push_back((Node){a, b, t, val});
}
}
cin >> lastVal;
for (int x = 0; x < 1 << k; x++) full.set(x);
for (int b = 0; b < 10; b++) {
S[b][0] = 0, S[b][3] = full;
for (int i = 0; i < 1 << k; i++) {
if (i >> b & 1) S[b][2].set(i);
else S[b][1].set(i);
}
}
for (int x = 0; x < 1 << k; x++) {
outEdge[x] = getLimit(x);
}
int ansA = 0, ansB = 0, ansC = 0;
for (int x = 0; x < (1 << k); x++) {
if (outEdge[x][x]) ansA++;
for (int y = 0; y < (1 << k); y++) if(outEdge[x][y]) {
if (outEdge[y][x]) ansB++;
ansC += (~outEdge[x] & outEdge[y]).count();
}
}
cout << ansA << ' ' << ansB << ' ' << ansC << '\n';
}
int main() {
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5612kb
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: 1ms
memory: 5552kb
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: 62ms
memory: 5676kb
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: 209ms
memory: 5928kb
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: 99ms
memory: 158368kb
input:
1 3 1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...
output:
4 16 0
result:
ok single line: '4 16 0'
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 5684kb
input:
1 1 1 1 x^y|1 0 1
output:
0 0 0
result:
wrong answer 1st lines differ - expected: '1 1 0', found: '0 0 0'