QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#698336 | #8770. Comparator | ucup-team5062# | AC ✓ | 853ms | 47628kb | C++17 | 4.3kb | 2024-11-01 18:58:54 | 2024-11-01 18:58:54 |
Judging History
answer
#include <array>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int parsing(const string& s) {
int pos = 0;
auto expr0 = [&](auto& expr0, auto& expr1, auto& expr2, auto& expr3, auto& expr4, auto& expr5) -> int {
/*
if (s[pos] == '0') {
pos++;
return 0;
}
if (s[pos] == '1') {
pos++;
return 1;
}
*/
return expr5(expr0, expr1, expr2, expr3, expr4, expr5);
};
auto expr1 = [&](auto& expr0, auto& expr1, auto& expr2, auto& expr3, auto& expr4, auto& expr5) -> int {
int res = expr5(expr0, expr1, expr2, expr3, expr4, expr5);
while (pos != int(s.size()) && s[pos] == '=') {
pos++;
int subres = expr5(expr0, expr1, expr2, expr3, expr4, expr5);
res ^= subres ^ 1;
}
return res;
};
auto expr2 = [&](auto& expr0, auto& expr1, auto& expr2, auto& expr3, auto& expr4, auto& expr5) -> int {
int res = expr1(expr0, expr1, expr2, expr3, expr4, expr5);
while (pos != int(s.size()) && s[pos] == '&') {
pos++;
int subres = expr1(expr0, expr1, expr2, expr3, expr4, expr5);
res &= subres;
}
return res;
};
auto expr3 = [&](auto& expr0, auto& expr1, auto& expr2, auto& expr3, auto& expr4, auto& expr5) -> int {
int res = expr2(expr0, expr1, expr2, expr3, expr4, expr5);
while (pos != int(s.size()) && s[pos] == '|') {
pos++;
int subres = expr2(expr0, expr1, expr2, expr3, expr4, expr5);
res |= subres;
}
return res;
};
auto expr4 = [&](auto& expr0, auto& expr1, auto& expr2, auto& expr3, auto& expr4, auto& expr5) -> int {
int res = expr3(expr0, expr1, expr2, expr3, expr4, expr5);
while (pos != int(s.size()) && s[pos] == '^') {
pos++;
int subres = expr3(expr0, expr1, expr2, expr3, expr4, expr5);
res ^= subres;
}
return res;
};
auto expr5 = [&](auto& expr0, auto& expr1, auto& expr2, auto& expr3, auto& expr4, auto& expr5) -> int {
if (s[pos] == '0') {
pos++;
return 0;
}
if (s[pos] == '1') {
pos++;
return 1;
}
if (s[pos] == '(') {
pos++;
int subres = expr4(expr0, expr1, expr2, expr3, expr4, expr5);
pos++;
return subres;
}
if (s[pos] == '!') {
pos++;
int subres = expr5(expr0, expr1, expr2, expr3, expr4, expr5);
return 1 - subres;
}
int res = expr5(expr0, expr1, expr2, expr3, expr4, expr5);
return res;
};
int ans = expr4(expr0, expr1, expr2, expr3, expr4, expr5);
return ans;
}
int main() {
// step #1. input
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<vector<vector<bool> > > finished(K, vector<vector<bool> >(K, vector<bool>(4, false)));
vector<array<int, 4> > seq;
for (int i = 0; i < N; i++) {
int a, b, c; string S;
cin >> a >> b >> S >> c;
a--; b--;
vector<int> ends;
for (char x = '0'; x <= '1'; x++) {
for (int y = '0'; y <= '1'; y++) {
string T = S;
for (int i = 0; i < int(S.size()); i++) {
if (S[i] == 'x') {
T[i] = x;
}
if (S[i] == 'y') {
T[i] = y;
}
}
int res = parsing(T);
if (res == 1) {
ends.push_back(int(x == '1') + int(y == '1') * 2);
}
}
}
for (int i : ends) {
if (!finished[a][b][i]) {
finished[a][b][i] = true;
seq.push_back({a, b, i, c});
}
}
}
int FINAL_VAL;
cin >> FINAL_VAL;
vector<vector<int> > g(1 << K, vector<int>(1 << K, -1));
for (array<int, 4> v : seq) {
for (int i = 0; i < (1 << K); i++) {
for (int j = 0; j < (1 << K); j++) {
if (g[i][j] == -1 && (((i >> v[0]) & 1) | (((j >> v[1]) & 1) << 1)) == v[2]) {
g[i][j] = v[3];
}
}
}
}
for (int i = 0; i < (1 << K); i++) {
for (int j = 0; j < (1 << K); j++) {
if (g[i][j] == -1) {
g[i][j] = FINAL_VAL;
}
}
}
int ans1 = 0, ans2 = 0, ans3 = 0;
for (int i = 0; i < (1 << K); i++) {
ans1 += int(g[i][i] == 1);
}
ans2 += ans1;
for (int i = 0; i < (1 << K); i++) {
for (int j = i + 1; j < (1 << K); j++) {
ans2 += int(g[i][j] + g[j][i] == 2) * 2;
}
}
for (int i = 0; i < (1 << K); i++) {
for (int j = 0; j < (1 << K); j++) {
for (int k = 0; k < (1 << K); k++) {
ans3 += int(g[i][j] == 1 && g[j][k] == 1 && g[i][k] == 0);
}
}
}
cout << ans1 << ' ' << ans2 << ' ' << ans3 << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
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: 3816kb
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: 45ms
memory: 3736kb
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: 853ms
memory: 7496kb
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: 11ms
memory: 5416kb
input:
1 3 1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...
output:
4 16 0
result:
ok single line: '4 16 0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3884kb
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: 3816kb
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: 3644kb
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: 11ms
memory: 7344kb
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: 3848kb
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: 31ms
memory: 47628kb
input:
1 1 1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
output:
1 1 0
result:
ok single line: '1 1 0'
Test #13:
score: 0
Accepted
time: 247ms
memory: 7308kb
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: 3884kb
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: 3536kb
input:
0 3 1
output:
8 64 0
result:
ok single line: '8 64 0'