QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#439397#8770. Comparatorucup-team045AC ✓243ms13488kbC++203.6kb2024-06-11 21:09:352024-06-11 21:09:36

Judging History

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

  • [2024-06-11 21:09:36]
  • 评测
  • 测评结果:AC
  • 用时:243ms
  • 内存:13488kb
  • [2024-06-11 21:09:35]
  • 提交

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['!'] = 5;
    mp['='] = 4;
    mp['&'] = 3;
    mp['|'] = 2;
    mp['^'] = 1;

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

    auto get = [&](string s, int x, int y){
        vector<int> nums;
        vector<char> ops;

        s = string(s.size(), '(') + s + ')';
        
        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);
            } 
        };
        
        char last;
        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 == '!'){
                    ops.push_back(c);
                }
                else{
                    while(!ops.empty() and ops.back() != '(' and mp[ops.back()] >= mp[c]) eval();
                    ops.push_back(c);
                }
            }
            last = c;
        }
        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: 1ms
memory: 3604kb

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

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: 29ms
memory: 3760kb

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: 243ms
memory: 7904kb

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: 20ms
memory: 13488kb

input:

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

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3764kb

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

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

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

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

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

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: 4ms
memory: 5044kb

input:

1 1
1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

1 1 0

result:

ok single line: '1 1 0'

Test #13:

score: 0
Accepted
time: 200ms
memory: 7768kb

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

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

input:

0 3
1

output:

8 64 0

result:

ok single line: '8 64 0'