QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#463081 | #8770. Comparator | ucup-team3519 | TL | 534ms | 36492kb | C++20 | 4.2kb | 2024-07-04 13:31:28 | 2024-07-04 13:31:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define all0(x) (x).begin(),(x).end()
#define all1(x) (x).begin()+1,(x).end()
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define cin std::cin
#define cout std::cout
typedef long long LL;
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
//const int MN = 2e5 + 20;//MaxN 记得改一下
const int INF = 2e9 + 1000;//INF
const LL INFLL = 8e18 + 1000;//INF long long
mt19937 mrand(random_device{}());
//模板区域~~~~~~~
//模板结束~~~~~~~
int get_pri (char c) {
if(c == '!') return 5;
if(c == '=') return 4;
if(c == '&') return 3;
if(c == '|') return 2;
if(c == '^') return 1;
assert(0);
}
array<int, 4> cal(array<int, 4> a, array<int, 4> b, char c) {
array<int, 4> ans;
for(int i = 0; i <= 3; i++) {
if(c == '=') ans[i] = a[i] == b[i];
if(c == '&') ans[i] = a[i] && b[i];
if(c == '|') ans[i] = a[i] || b[i];
if(c == '^') ans[i] = a[i] ^ b[i];
if(c == '!') ans[i] = !b[i];
}
return ans;
}
void show(array<int, 4> a) {
cout << "[" << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << "]" << endl;
}
struct node {
char type;
int priority;
bool hav;
array<int, 4> tab;
};
void show (node x){
cout << x.type << " " << x.priority << " " << x.hav << " ";
show(x.tab);
}
array<int, 4> deal(string s) {
int n = s.size() - 1;
V<node> stk;
stk.pb({});
int base = 0;
for(int i = 1; i <= n + 1; i++) {
if(i == n + 1) stk.pb({});
else if(s[i] == '(') base += 10;
else if(s[i] == ')') base -= 10;
else if(s[i] == '1') stk.back().hav = 1, stk.back().tab = {1, 1, 1, 1};
else if(s[i] == '0') stk.back().hav = 1, stk.back().tab = {0, 0, 0, 0};
else if(s[i] == 'x') stk.back().hav = 1, stk.back().tab = {0, 1, 0, 1};
else if(s[i] == 'y') stk.back().hav = 1, stk.back().tab = {0, 0, 1, 1};
else {
stk.pb({s[i], get_pri(s[i]) + base, 0});
}
while(stk.size() >= 3 && stk[stk.size() - 2].priority >= stk[stk.size() - 3].priority
&& stk[stk.size() - 2].priority > stk[stk.size() - 1].priority) {
stk[stk.size() - 3].tab = cal(stk[stk.size() - 3].tab, stk[stk.size() - 2].tab, stk[stk.size() - 2].type);
stk[stk.size() - 2] = stk[stk.size() - 1];
stk.pop_back();
}
}
return stk[0].tab;
}
void solve() {
int n, k; cin >> n >> k;
struct info{
int a, b;
array<int, 4> tab;
int r;
};
V<info> a(n + 1);
for(int i = 1; i <= n; i++) {
string s;
cin >> a[i].a >> a[i].b >> s >> a[i].r;
s = " " + s;
a[i].tab = deal(s);
// show(a[i].tab);
}
int t; cin >> t;
a.pb({1, 1, {1, 1, 1, 1}, t});
n++;
V<V<int>> result(1 << k, V<int>(1 << k));
for(int i = 0; i < 1 << k; i++) {
for(int j = 0; j < 1 << k; j++) {
int ans;
for(int t = 1; t <= n; t++) {
if(a[t].tab[(i >> a[t].a - 1 & 1) + 2 * (j >> a[t].b - 1 & 1)]) {
ans = a[t].r;
break;
}
}
result[i][j] = ans;
}
}
// for(int i = 0; i < 1 << k; i++) {
// for(int j = 0; j < 1 << k ;j++) {
// cout << result[i][j] << " \n"[j == (1 << k) - 1];
// }
// }
int a1 = 0;
for(int i = 0; i < 1 << k; i++) if(result[i][i]) a1++;
int a2 = 0;
for(int i = 0; i < 1 << k; i++) {
for(int j = 0; j < 1 << k; j++) {
if(result[i][j] && result[j][i]) a2++;
}
}
int a3 = 0;
for(int i = 0; i < 1 << k; i++) {
for(int j = 0; j < 1 << k; j++) {
if(!result[i][j]) continue;
for(int t = 0; t < 1 << k; t++) {
a3 += result[j][t] && !result[i][t];
}
}
}
cout << a1 << " " << a2 << " " << a3 << endl;
}
int32_t main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int tt=1;
//cin >> tt;
while (tt--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
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: 3544kb
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: 17ms
memory: 3716kb
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: 534ms
memory: 13936kb
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: 19ms
memory: 36492kb
input:
1 3 1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...
output:
4 16 0
result:
ok single line: '4 16 0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3612kb
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: 3560kb
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: 3660kb
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: 3768kb
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: 7ms
memory: 7576kb
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: 3540kb
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: 3808kb
input:
1 1 1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
output:
1 1 0
result:
ok single line: '1 1 0'
Test #13:
score: -100
Time Limit Exceeded
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...