QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#536020 | #8770. Comparator | RngBased | RE | 1ms | 5696kb | C++20 | 4.4kb | 2024-08-28 17:39:08 | 2024-08-28 17:39:08 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
int n, k, cond[10][10][2][2], test[10][2][(1 << 10) + 1], U[200015], V[200015], C[200005];
bool ed, argue[200015][2][2];
bitset<1024> f[1024], rf[1024];
vector<int> pos[11][11];
int pri(char c){
if (c == '(') return 6;
else if (c == '!') return 1;
else if (c == '=') return 2;
else if (c == '&') return 3;
else if (c == '|') return 4;
else return 5;
}
bool solve(string s, bool b1, bool b2){
s = '(' + s + ')';
vector<char> res, st;
for (auto i : s){
if (i == '(')
st.emplace_back(i);
else if (i == ')'){
while (st.back() != '(')
res.emplace_back(st.back()), st.pop_back();
st.pop_back();
}
else if (i == '!' || i == '=' || i == '^' || i == '&' || i == '|'){
while (pri(st.back()) <= pri(i))
res.emplace_back(st.back()), st.pop_back();
st.emplace_back(i);
}
else {
if (i == '0' || i == '1')
res.emplace_back(i);
else if (i == 'x')
res.emplace_back('0' + b1);
else res.emplace_back('0' + b2);
while (!st.empty() && st.back() == '!')
res.emplace_back(st.back()), st.pop_back();
}
}
vector<int> cnt;
for (auto i : res){
if (i == '0' || i == '1')
cnt.emplace_back(i - '0');
else if (i == '!')
assert(cnt.size() >= 1), cnt.back() ^= 1;
else {
assert(cnt.size() >= 2);
int c1 = cnt.back(); cnt.pop_back();
int c2 = cnt.back(); cnt.pop_back();
if (i == '=')
cnt.emplace_back(c1 == c2);
if (i == '&')
cnt.emplace_back(c1 & c2);
if (i == '|')
cnt.emplace_back(c1 | c2);
if (i == '^')
cnt.emplace_back(c1 ^ c2);
}
}
assert(cnt.size() == 1);
return cnt.back();
}
// int checker(int a, int b){
// for (int i = 1; i <= n; i++){
// if (argue[i][a >> U[i] & 1][b >> V[i] & 1])
// return i;
// }
// return n + 1;
// }
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++){
int u, v, c;
string s;
cin >> u >> v >> s >> c;
u--; v--;
pos[u][v].emplace_back(i);
U[i] = u, V[i] = v, C[i] = c;
for (int j = 0; j <= 1; j++)
for (int h = 0; h <= 1; h++)
argue[i][j][h] = solve(s, j, h);
}
cin >> ed;
C[n + 1] = argue[n + 1][0][0] = argue[n + 1][0][1] = argue[n + 1][1][0] = argue[n + 1][1][1] = ed;
for (int i = 0; i < k; i++){
for (int j = 0; j < k; j++){
for (int x = 0; x <= 1; x++){
for (int y = 0; y <= 1; y++){
cond[i][j][x][y] = n + 1;
for (auto h : pos[i][j]){
if (argue[h][x][y]){
cond[i][j][x][y] = h;
break;
}
}
}
}
}
}
for (int i = 0; i < k; i++){
for (int x = 0; x <= 1; x++){
for (int j = 0; j < (1 << k); j++){
test[i][x][j] = n + 1;
for (int l = 0; l < k; l++)
test[i][x][j] = min(test[i][x][j], cond[i][l][x][(j >> l) & 1]);
}
}
}
for (int i = 0; i < (1 << k); i++){
for (int j = 0; j < (1 << k); j++){
int stop = n + 1;
for (int l = 0; l < k; l++)
stop = min(stop, test[l][i >> l & 1][j]);
f[i][j] = rf[j][i] = C[stop];
}
}
ll ans1 = 0, ans2 = 0, ans3 = 0;
for (int i = 0; i < (1 << k); i++){
ans1 += (f[i][i] != 0);
for (int j = 0; j < (1 << k); j++){
ans2 += (f[i][j] == 1 && f[j][i] == 1);
if (f[i][j] == 0)
ans3 += (f[i] & rf[j]).count();
}
}
cout << ans1 << " " << ans2 << " " << ans3 << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5612kb
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: 1ms
memory: 5696kb
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: -100
Runtime Error
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...