QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#439380#8770. Comparatorucup-team045WA 166ms7968kbC++203.6kb2024-06-11 20:48:502024-06-11 20:48:51

Judging History

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

  • [2024-06-11 20:48:51]
  • 评测
  • 测评结果:WA
  • 用时:166ms
  • 内存:7968kb
  • [2024-06-11 20:48:50]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<array>
#include<set>
#include<bitset>
using namespace std;
using LL = long long;
bitset<1 << 10> bs[1 << 10][2];

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int mp[256]{};

    mp['!'] = 2;
    mp['='] = mp['&'] = mp['|'] = mp['^'] = 1;

    int n, m;
    cin >> n >> m;

    auto get = [&](string s, int x, int y){
        vector<int> nums;
        vector<char> ops;
        
        auto eval = [&](){
            char op = ops.back();
            ops.pop_back();
            if (op == '!'){
                nums.back() ^= 1;
            }
            else{
                int t1 = nums.back();
                nums.pop_back();
                int t2 = nums.back();
                nums.pop_back();
                if (op == '=') nums.push_back(t1 == t2);
                if (op == '&') nums.push_back(t1 & t2);
                if (op == '|') nums.push_back(t1 | t2);
                if (op == '^') nums.push_back(t1 ^ t2);
            } 
        };
        
        for(auto c : s){
            if (isdigit(c)){
                nums.push_back(c - '0');
            }
            else if (c == 'x'){
                nums.push_back(x);
            }
            else if (c == 'y'){
                nums.push_back(y);
            }
            else if (c == '('){
                ops.push_back('(');
            }
            else if (c == ')'){
                while(ops.back() != '(') eval();
                ops.pop_back();
            }
            else{
                 if (c == '!'){
                    if (!ops.empty() and ops.back() == '!') ops.pop_back();
                    else ops.push_back('!');
                }
                else{
                    while(!ops.empty() and ops.back() != '(' and mp[ops.back()] >= mp[c]) eval();
                    ops.push_back(c);
                }
            }
        }
        while(!ops.empty()) eval();
        return nums.back();
    };

    set<array<int, 4> > st;
    vector<array<int, 4> > p;
    for(int i = 0; i < n; i++){
        int a, b, d; string s;
        cin >> a >> b >> s >> d;
        a--, b--;
        int c = 0;
        for(int j = 0; j < 4; j++){
            int x = j % 2, y = j / 2;
            c |= get(s, x, y) << j;
        }
        if (!st.contains({a, b, c, d})){
            st.insert({a, b, c, d});
            p.push_back({a, b, c, d});
        }
    }
    int k;
    cin >> k;

    auto f = [&](int x, int y){
        for(auto &[a, b, c, d] : p){
            int bit1 = x >> a & 1;
            int bit2 = y >> b & 1;
            if (c >> (bit1 + bit2 * 2) & 1){
                return d;
            }
        }
        return k;
    };

    vector<vector<int> > a(1 << m, vector<int>(1 << m));
    for(int i = 0; i < 1 << m; i++){
        for(int j = 0; j < 1 << m; j++){
            a[i][j] = f(i, j);
            bs[i][a[i][j]].set(j);
        }
    }

    int cnt1 = 0, cnt2 = 0, cnt3 = 0;
    for(int i = 0; i < 1 << m; i++){
        cnt1 += a[i][i];
    }
    for(int i = 0; i < 1 << m; i++){
        for(int j = 0; j < 1 << m; j++){
            if (a[i][j] == 1 and a[j][i] != 0){
                cnt2 += 1;
            }
        }
    }
    for(int i = 0; i < 1 << m; i++){
        for(int j = 0; j < 1 << m; j++){
            if (a[i][j]){
                cnt3 += (bs[j][1] & bs[i][0]).count();
            }
        }
    }
    cout << cnt1 << ' ' << cnt2 << ' ' << cnt3 << '\n';

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 25ms
memory: 3916kb

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: 166ms
memory: 7968kb

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: 6ms
memory: 5228kb

input:

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

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3600kb

input:

1 1
1 1 x^y|1 0
1

output:

0 0 0

result:

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