QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#439379#8770. Comparatorucup-team045WA 1ms3840kbC++203.6kb2024-06-11 20:46:412024-06-11 20:46:41

Judging History

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

  • [2024-06-11 20:46:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3840kb
  • [2024-06-11 20:46:41]
  • 提交

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();
                }
            }
        }
        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: 0
Wrong Answer
time: 1ms
memory: 3840kb

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:

4 16 0

result:

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