QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#454795#8770. Comparatorucup-team173WA 230ms268008kbC++236.3kb2024-06-25 14:19:022024-06-25 14:19:04

Judging History

你现在查看的是最新测评结果

  • [2024-06-25 14:19:04]
  • 评测
  • 测评结果:WA
  • 用时:230ms
  • 内存:268008kb
  • [2024-06-25 14:19:02]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e6 + 5;

int pos, len, lastVal;
string str;
int tot = 0, ty[MAXN], ch[MAXN][2];


int buildCalc(int opt1, vector<int> tt, vector<int> op) ;
int build(vector<int> tt, vector<int> op) ;
int buildExpress();

int dfs(int x, int val_x, int val_y) {
    if (ty[x] == 2) return val_x;
    if (ty[x] == 3) return val_y;
    if (ty[x] >= 0) return ty[x];
    if (ty[x] == -1) return !dfs(ch[x][0], val_x, val_y);
    int val1 = dfs(ch[x][0], val_x, val_y);
    int val2 = dfs(ch[x][1], val_x, val_y);
    if (ty[x] == -2) return val1 & val2;
    if (ty[x] == -3) return val1 | val2;
    if (ty[x] == -4) return val1 ^ val2;
    if (ty[x] == -5) return val1 == val2;
}

void print(int x) {
    cout << x << ':';
    if (ty[x] >= 0) {
        cout << ty[x] << '\n';
        return ;
    }
    if (ty[x] == -1) {
        cout << ty[x] << ' ' << ch[x][0] << '\n';
        return print(ch[x][0]);
    }        
    cout << ty[x] << ' ' << ch[x][0] << ' ' << ch[x][1] << '\n';
    print(ch[x][0]), print(ch[x][1]);
}

int calc(string s) {
    pos = 0, str = s, len = str.size();
    tot = 0;
    int rt = buildExpress(), sta = 0;
    // print(rt);
    for (int x = 0; x <= 1; x++) {
        for (int y = 0; y <= 1; y++) {
            if (dfs(rt, x, y)) sta |= 1 << (x << 1 | y);
        }
    }
    return sta;
}

struct Node {
    int a, b, sta, val;
};

vector<Node> f;
map<pair<pair<int, int>, int>, bool> tt;

bitset<1024> S[10][4], full;

bitset<1024> getLimit(int A) {
    bitset<1024> now = full, lim = 0;
    for (auto node : f) {
        int a = node.a, b = node.b, sta = node.sta, val = node.val;
        int x = A >> a & 1, pp = 0;
        for (int y = 0; y <= 1; y++) {
            if (sta >> (x << 1 | y) & 1) {
                pp |= 1 << y;
            } 
        }
        if (val == 1) {
            lim |= now & S[b][pp];
        }
        now &= S[b][pp ^ 3];
    }
    if (lastVal) {
        lim |= now;
    }
    return lim;
}

bitset<1024> outEdge[1024];

void solve() {
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        int a, b, val;
        string s;
        cin >> a >> b >> s >> val;
        a--, b--;
        int t = calc(s);
        if (tt.find(make_pair(make_pair(a, b), t)) == tt.end()) {
            tt[make_pair(make_pair(a, b), t)] = 1;
            f.push_back((Node){a, b, t, val});
        }
    }
    cin >> lastVal;
    for (int x = 0; x < 1 << k; x++) full.set(x);
    for (int b = 0; b < 10; b++) {
        S[b][0] = 0, S[b][3] = full;
        for (int i = 0; i < 1 << k; i++) {
            if (i >> b & 1) S[b][2].set(i);
            else S[b][1].set(i);
        }
        
    }
    for (int x = 0; x < 1 << k; x++) {
        outEdge[x] = getLimit(x);
    }
    int ansA = 0, ansB = 0, ansC = 0;
    for (int x = 0; x < (1 << k); x++) {
        if (outEdge[x][x]) ansA++;
        for (int y = 0; y < (1 << k); y++) if(outEdge[x][y]) {
            if (outEdge[y][x]) ansB++;
            ansC += (~outEdge[x] & outEdge[y]).count();
        }
    }
    cout << ansA << ' ' << ansB << ' ' << ansC << '\n';
}

int main() {
    solve();
    return 0;
}


int buildCalc(int opt1, vector<int> tt, vector<int> op) {
    int flag = 0;
    for (auto opt : op) if (opt == opt1) flag = 1;
    if (flag) {
        vector<int> pos;
        for (int i = 0; i < op.size(); i++) {
            if (op[i] == opt1) pos.push_back(i);
        }
        vector<int> s;
        int last = -1;
        for (auto o : pos) {
            s.push_back(build(vector<int>(tt.begin() + last + 1, tt.begin() + o + 1), vector<int>(op.begin() + last + 1, op.begin() + o)));
            last = o;
        }
        s.push_back(build(vector<int>(tt.begin() + last + 1, tt.end()), vector<int>(op.begin() + last + 1, op.end())));
        last = s[0];
        for (int i = 1; i < s.size(); i++) {
            int t = ++tot;
            ty[t] = opt1;
            ch[t][0] = last;
            ch[t][1] = s[i];
            last = t;
        }
        return last;
    } else {
        return -1;
    }
}

int getPriority(int op) {
    return op == -5 ? 4 : op == -2 ? 3 : op == -3 ? 2 : 1;
}

bool compare(int op1, int op2) {
    return getPriority(op1) < getPriority(op2);
}

int build(vector<int> tt, vector<int> op) {
    if (op.empty()) {
        return tt[0];
    }
    vector<int> stackNode, stackOp;
    stackNode.push_back(tt[0]);
    for (int i = 0; i < op.size(); i++) {
        while(!stackOp.empty() && !compare(stackOp.back(), op[i])) {
            int t2 = stackNode.back();
            stackNode.pop_back();
            int t1 = stackNode.back();
            stackNode.pop_back();
            int opt = stackOp.back();
            stackOp.pop_back();
            int t = ++tot;
            ty[t] = opt, ch[t][0] = t1, ch[t][1] = t2;
            stackNode.push_back(t);
        }
        stackOp.push_back(op[i]);
        stackNode.push_back(tt[i + 1]);
    }
    while(!stackOp.empty()) {
        int t2 = stackNode.back();
        stackNode.pop_back();
        int t1 = stackNode.back();
        stackNode.pop_back();
        int opt = stackOp.back();
        stackOp.pop_back();
        int t = ++tot;
        ty[t] = opt, ch[t][0] = t1, ch[t][1] = t2;
        stackNode.push_back(t);
    }
    return stackNode[0];
}

int buildExpress() {
    vector<int> tt, op;
    while (pos < len) {
        if (str[pos] == '(') pos++, tt.push_back(buildExpress());
        else if (str[pos] == '!') pos++, ty[++tot] = -1, tt.push_back(tot), ch[tot][0] = buildExpress();
        else if (str[pos] == 'x') ty[++tot] = 2, tt.push_back(tot), pos++;
        else if (str[pos] == 'y') ty[++tot] = 3, tt.push_back(tot), pos++;
        else if (str[pos] == '0') ty[++tot] = 0, tt.push_back(tot), pos++;
        else if (str[pos] == '1') ty[++tot] = 1, tt.push_back(tot), pos++;
        else if (str[pos] == '&') op.push_back(-2), pos++;
        else if (str[pos] == '|') op.push_back(-3), pos++;
        else if (str[pos] == '^') op.push_back(-4), pos++;
        else if (str[pos] == '=') op.push_back(-5), pos++;
        else if(str[pos] == ')') {
            pos++;
            break;
        }
    }
    return build(tt, op);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7712kb

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: 5812kb

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: 77ms
memory: 5796kb

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: 230ms
memory: 6080kb

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: 144ms
memory: 268008kb

input:

1 3
1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 5584kb

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: 7708kb

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: 1ms
memory: 5524kb

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: 5676kb

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: -100
Wrong Answer
time: 17ms
memory: 8444kb

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:

256 65536 0

result:

wrong answer 1st lines differ - expected: '0 0 0', found: '256 65536 0'