QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#428536 | #8770. Comparator | ucup-team180# | AC ✓ | 146ms | 22416kb | C++17 | 3.2kb | 2024-06-01 20:09:54 | 2024-06-01 20:09:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int number(string &S, int x, int y, int &p){
char c = S[p];
p++;
if (c == 'x'){
return x;
}
if (c == 'y'){
return y;
}
if (c == '0'){
return 0;
}
if (c == '1'){
return 1;
}
}
int expr(string &S, int x, int y, int &p);
int term(string &S, int x, int y, int &p){
int neg = 0;
while (S[p] == '!'){
neg ^= 1;
p++;
}
if (S[p] == '('){
p++;
int ans = expr(S, x, y, p);
p++;
return ans ^ neg;;
} else {
return number(S, x, y, p) ^ neg;
}
}
int expr_eq(string &S, int x, int y, int &p){
int ans = term(S, x, y, p);
while (S[p] == '='){
p++;
int ans2 = term(S, x, y, p);
ans = ans == ans2;
}
return ans;
}
int expr_and(string &S, int x, int y, int &p){
int ans = expr_eq(S, x, y, p);
while (S[p] == '&'){
p++;
int ans2 = expr_eq(S, x, y, p);
ans = ans & ans2;
}
return ans;
}
int expr_or(string &S, int x, int y, int &p){
int ans = expr_and(S, x, y, p);
while (S[p] == '|'){
p++;
int ans2 = expr_and(S, x, y, p);
ans = ans | ans2;
}
return ans;
}
int expr(string &S, int x, int y, int &p){
int ans = expr_or(S, x, y, p);
while (S[p] == '^'){
p++;
int ans2 = expr_or(S, x, y, p);
ans = ans ^ ans2;
}
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector<int> a(n), b(n);
vector<string> s(n);
vector<int> r(n + 1);
for (int i = 0; i < n; i++){
cin >> a[i] >> b[i] >> s[i] >> r[i];
a[i]--;
b[i]--;
}
cin >> r[n];
vector<vector<array<array<int, 2>, 2>>> A(k, vector<array<array<int, 2>, 2>>(k));
for (int i = 0; i < k; i++){
for (int j = 0; j < k; j++){
for (int l = 0; l < 2; l++){
for (int m = 0; m < 2; m++){
A[i][j][l][m] = n;
}
}
}
}
for (int i = n - 1; i >= 0; i--){
for (int j = 0; j < 2; j++){
for (int l = 0; l < 2; l++){
int p = 0;
if (expr(s[i], j, l, p) == 1){
A[a[i]][b[i]][j][l] = i;
}
}
}
}
vector<vector<int>> f(1 << k, vector<int>(1 << k, 0));
for (int i = 0; i < (1 << k); i++){
for (int j = 0; j < (1 << k); j++){
int mn = n;
for (int l = 0; l < k; l++){
for (int m = 0; m < k; m++){
mn = min(mn, A[l][m][i >> l & 1][j >> m & 1]);
}
}
f[i][j] = r[mn];
}
}
int ans1 = 0;
for (int i = 0; i < (1 << k); i++){
if (f[i][i] == 1){
ans1++;
}
}
int ans2 = 0;
for (int i = 0; i < (1 << k); i++){
for (int j = 0; j < (1 << k); j++){
if (f[i][j] == 1 && f[j][i] == 1){
ans2++;
}
}
}
int ans3 = 0;
vector<bitset<1024>> B1(1 << k), B2(1 << k);
for (int i = 0; i < (1 << k); i++){
for (int j = 0; j < (1 << k); j++){
if (f[i][j] == 1){
B1[i].set(j);
B2[j].set(i);
}
}
}
for (int i = 0; i < (1 << k); i++){
for (int j = 0; j < (1 << k); j++){
if (f[i][j] == 0){
ans3 += (B1[i] & B2[j]).count();
}
}
}
cout << ans1 << ' ' << ans2 << ' ' << ans3 << endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3856kb
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: 3648kb
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: 25ms
memory: 4972kb
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: 146ms
memory: 15368kb
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: 3ms
memory: 4292kb
input:
1 3 1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...
output:
4 16 0
result:
ok single line: '4 16 0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3620kb
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: 3844kb
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: 3840kb
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: 3544kb
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: 137ms
memory: 7684kb
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: 3556kb
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: 15ms
memory: 22416kb
input:
1 1 1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
output:
1 1 0
result:
ok single line: '1 1 0'
Test #13:
score: 0
Accepted
time: 143ms
memory: 16180kb
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: 3504kb
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: 3652kb
input:
0 3 1
output:
8 64 0
result:
ok single line: '8 64 0'