QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#429496 | #8770. Comparator | KKT89 | AC ✓ | 1336ms | 35044kb | C++14 | 4.6kb | 2024-06-02 16:10:15 | 2024-06-02 16:10:15 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n,k; cin >> n >> k;
vector<vector<vector<int>>> calc(k, vector<vector<int>>(k, vector<int>(4, -1)));
vector<tuple<int,int,int,int>> memo;
for (int i = 0; i < n; ++i) {
int a,b; cin >> a >> b;
a -= 1, b -= 1;
string s; cin >> s;
int res; cin >> res;
for (int j = 0; j < 4; ++j) {
if (calc[a][b][j] != -1) continue;
int x = (j&1), y = (j&2)/2;
auto f = [&](auto f, int &idx) -> int {
vector<int> val;
vector<char> op;
int no = 0;
while (idx < s.size()) {
if (s[idx] == '(') {
idx += 1;
val.push_back(f(f, idx) ^ no);
} else if (s[idx] == ')') {
idx += 1;
break;
} else if (s[idx] == '!') {
no ^= 1;
idx += 1;
} else if (s[idx] == 'x') {
val.push_back(x ^ no);
idx += 1;
} else if (s[idx] == 'y') {
val.push_back(y ^ no);
idx += 1;
} else if (isdigit(s[idx])) {
val.push_back((s[idx] - '0') ^ no);
idx += 1;
} else {
op.push_back(s[idx]);
no = 0;
idx += 1;
}
}
for (char c : vector<char>{'=', '&', '|', '^'}) {
vector<int> n_val = {val[0]};
vector<char> n_op;
for (int l = 0; l < op.size(); ++l) {
if (op[l] == c) {
if (c == '=') {
n_val.back() = (n_val.back() == val[l+1]);
} else if (c == '&') {
n_val.back() = (n_val.back() & val[l+1]);
} else if (c == '|') {
n_val.back() = (n_val.back() | val[l+1]);
} else {
n_val.back() = (n_val.back() ^ val[l+1]);
}
} else {
n_val.push_back(val[l+1]);
n_op.push_back(op[l]);
}
}
swap(val, n_val);
swap(op, n_op);
}
return val[0];
};
int idx = 0;
int uo = f(f, idx);
if (uo) {
calc[a][b][j] = res;
memo.emplace_back(a, b, j, res);
}
}
}
{
int res; cin >> res;
for (int i = 0; i < k; ++i) {
for (int j = 0; j < k; ++j) {
for (int l = 0; l < 4; ++l) {
if (calc[i][j][l] == -1) {
calc[i][j][l] = res;
memo.emplace_back(i, j, l, res);
}
}
}
}
}
vector<vector<bool>> dp(1<<k, vector<bool>(1<<k));
vector<vector<bool>> used(1<<k, vector<bool>(1<<k));
for (auto [a, b, c, d] : memo) {
for (int i = 0; i < (1<<k); ++i) {
for (int j = 0; j < (1<<k); ++j) {
if (used[i][j]) continue;
int x = ((1<<a)&i ? 1 : 0);
int y = ((1<<b)&j ? 2 : 0);
if (x + y == c) {
dp[i][j] = d;
used[i][j] = true;
}
}
}
}
int r1 = 0, r2 = 0, r3 = 0;
for (int i = 0; i < (1<<k); ++i) {
if (dp[i][i]) r1 += 1;
}
for (int i = 0; i < (1<<k); ++i) {
for (int j = 0; j < (1<<k); ++j) {
if (dp[i][j]) {
if (dp[j][i]) r2 += 1;
}
}
}
for (int i = 0; i < (1<<k); ++i) {
for (int j = 0; j < (1<<k); ++j) {
if (!dp[i][j]) continue;
for (int l = 0; l < (1<<k); ++l) {
if (!dp[j][l]) continue;
if (!dp[i][l]) r3 += 1;
}
}
}
cout << r1 << " " << r2 << " " << r3 << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
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: 3760kb
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: 1ms
memory: 3576kb
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: 1336ms
memory: 3844kb
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: 4148kb
input:
1 3 1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...
output:
4 16 0
result:
ok single line: '4 16 0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3580kb
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: 3592kb
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: 3516kb
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: 3508kb
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: 390ms
memory: 4168kb
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: 3760kb
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: 39ms
memory: 35044kb
input:
1 1 1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
output:
1 1 0
result:
ok single line: '1 1 0'
Test #13:
score: 0
Accepted
time: 954ms
memory: 3840kb
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: 3608kb
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: 3520kb
input:
0 3 1
output:
8 64 0
result:
ok single line: '8 64 0'