QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#427644 | #8770. Comparator | ucup-team004# | AC ✓ | 281ms | 7224kb | C++20 | 4.3kb | 2024-06-01 14:33:35 | 2024-06-01 14:33:36 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
constexpr int K = 1024;
int priority(char c) {
if (c == '(') {
return -1;
} else if (c == '!') {
return 5;
} else if (c == '=') {
return 4;
} else if (c == '&') {
return 3;
} else if (c == '|') {
return 2;
} else if (c == '^') {
return 1;
}
return 10;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, k;
std::cin >> n >> k;
std::vector vis(k, std::vector(k, std::array<std::array<int, 2>, 2>{}));
std::vector f(1 << k, std::bitset<K>{});
std::vector vf(1 << k, std::bitset<K>{});
for (int i = 0; i < n; i++) {
int a, b;
std::string expr;
int r;
std::cin >> a >> b >> expr >> r;
a--, b--;
std::vector<char> stk;
std::string suf;
for (auto c : expr) {
if (c == 'x' || c == 'y' || c == '0' || c == '1') {
stk.push_back(c);
} else if (c == '(') {
stk.push_back(c);
} else if (c == ')'){
while (stk.back() != '(') {
suf += stk.back();
stk.pop_back();
}
stk.pop_back();
} else {
while (!stk.empty() && priority(c) < priority(stk.back())) {
suf += stk.back();
stk.pop_back();
}
stk.push_back(c);
}
}
while (!stk.empty()) {
suf += stk.back();
stk.pop_back();
}
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
if (vis[a][b][x][y]) {
continue;
}
std::vector<int> v;
for (auto c : suf) {
if (c == '0') {
v.push_back(0);
} else if (c == '1') {
v.push_back(1);
} else if (c == 'x') {
v.push_back(x);
} else if (c == 'y') {
v.push_back(y);
} else if (c == '!') {
v.back() ^= 1;
} else {
int a = v.back();
v.pop_back();
int b = v.back();
v.pop_back();
if (c == '=') {
v.push_back(a == b);
} else if (c == '&') {
v.push_back(a & b);
} else if (c == '|') {
v.push_back(a | b);
} else if (c == '^') {
v.push_back(a ^ b);
}
}
}
assert(v.size() == 1);
if (v[0]) {
vis[a][b][x][y] = 1;
for (int i = 0; i < (1 << k); i++) {
if ((i >> a & 1) == x) {
for (int j = 0; j < (1 << k); j++) {
if ((j >> b & 1) == y && !vf[i][j]) {
f[i][j] = r;
vf[i][j] = 1;
}
}
}
}
}
}
}
}
int r;
std::cin >> r;
for (int i = 0; i < (1 << k); i++) {
for (int j = 0; j < (1 << k); j++) {
if (!vf[i][j]) {
vf[i][j] = 1;
f[i][j] = r;
}
}
}
int ans1 = 0, ans2 = 0, ans3 = 0;
for (int x = 0; x < (1 << k); x++) {
if (f[x][x]) {
ans1++;
}
for (int y = 0; y < (1 << k); y++) {
if (f[x][y] && f[y][x]) {
ans2++;
}
if (f[x][y]) {
ans3 += (f[y] & ~f[x]).count();
}
}
}
std::cout << ans1 << " " << ans2 << " " << ans3 << "\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
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: 3584kb
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: 15ms
memory: 3624kb
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: 281ms
memory: 3592kb
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: 8ms
memory: 7224kb
input:
1 3 1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...
output:
4 16 0
result:
ok single line: '4 16 0'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3588kb
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: 3616kb
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: 1ms
memory: 3652kb
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: 3816kb
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: 10ms
memory: 4080kb
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: 3880kb
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: 1ms
memory: 3980kb
input:
1 1 1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
output:
1 1 0
result:
ok single line: '1 1 0'
Test #13:
score: 0
Accepted
time: 84ms
memory: 3648kb
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: 3588kb
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: 3648kb
input:
0 3 1
output:
8 64 0
result:
ok single line: '8 64 0'