QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#463068#8770. Comparatorucup-team3519WA 531ms15132kbC++204.5kb2024-07-04 13:12:292024-07-04 13:12:30

Judging History

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

  • [2024-07-04 13:12:30]
  • 评测
  • 测评结果:WA
  • 用时:531ms
  • 内存:15132kb
  • [2024-07-04 13:12:29]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define V vector
#define all0(x) (x).begin(),(x).end()
#define all1(x) (x).begin()+1,(x).end()
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define cin std::cin
#define cout std::cout
typedef long long LL;
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;

//const int MN = 2e5 + 20;//MaxN 记得改一下
const int INF = 2e9 + 1000;//INF
const LL INFLL = 8e18 + 1000;//INF long long 
mt19937 mrand(random_device{}());
//模板区域~~~~~~~

//模板结束~~~~~~~

int get_pri (char c) {
    if(c == '!') return 5;
    if(c == '=') return 4;
    if(c == '&') return 3;
    if(c == '|') return 2;
    if(c == '^') return 1;
    assert(0);
}

array<int, 4> cal(array<int, 4> a, array<int, 4> b, char c) {
    array<int, 4> ans;
    for(int i = 0; i <= 3; i++) {
        if(c == '=') ans[i] = a[i] == b[i];
        if(c == '&') ans[i] = a[i] && b[i];
        if(c == '|') ans[i] = a[i] || b[i];
        if(c == '^') ans[i] = a[i] ^ b[i];
        if(c == '!') ans[i] = !b[i];
    }
    return ans;
}

void show(array<int, 4> a) {
    cout << "[" << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << "]" << endl;
}
struct node {
    char type;
    int priority;
    bool hav;
    array<int, 4> tab;
};
void show (node x){
    cout << x.type << " " << x.priority << " " << x.hav << " ";
    show(x.tab);
}

array<int, 4> deal(string s) {
    int n = s.size() - 1;
    V<node> stk;
    stk.pb({});
    int base = 0;
    for(int i = 1; i <= n + 1; i++) {
        if(i == n + 1) stk.pb({});
        else if(s[i] == '(') base += 10;
        else if(s[i] == ')') base -= 10;
        else if(s[i] == '1') stk.back().hav = 1, stk.back().tab = {1, 1, 1, 1};
        else if(s[i] == '0') stk.back().hav = 1, stk.back().tab = {0, 0, 0, 0};
        else if(s[i] == 'x') stk.back().hav = 1, stk.back().tab = {0, 1, 0, 1};
        else if(s[i] == 'y') stk.back().hav = 1, stk.back().tab = {0, 0, 1, 1};
        else {
            if(s[i] == '!' && stk.back().type == '!') stk.pop_back();
            else stk.pb({s[i], get_pri(s[i]) + base, 0});
        }
        
        // cout << i << " pack : " << endl;
        // for(auto s : stk) show(s);

        while(stk.size() >= 3 && stk[stk.size() - 2].priority >= stk[stk.size() - 3].priority 
        && stk[stk.size() - 2].priority >= stk[stk.size() - 1].priority) {
            stk[stk.size() - 3].tab = cal(stk[stk.size() - 3].tab, stk[stk.size() - 2].tab, stk[stk.size() - 2].type);
            stk[stk.size() - 2] = stk[stk.size() - 1];
            stk.pop_back();
        }
    }
    return stk[0].tab;
}



void solve() {

    // show(deal(" x&(x|!y)&!!!y"));    

    int n, k; cin >> n >> k;
    struct info{
        int a, b;
        array<int, 4> tab;
        int r;
    };

    V<info> a(n + 1);
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> a[i].a >> a[i].b >> s >> a[i].r;
        s = " " + s;
        a[i].tab = deal(s);
        // show(a[i].tab);
    }
    int t; cin >> t;
    a.pb({1, 1, {1, 1, 1, 1}, t});
    n++;

    V<V<int>> result(1 << k, V<int>(1 << k));
    for(int i = 0; i < 1 << k; i++) {
        for(int j = 0; j < 1 << k; j++) {
            int ans;
            for(int t = 1; t <= n; t++) {
                if(a[t].tab[(i >> a[t].a - 1 & 1) + 2 * (j >> a[t].b - 1 & 1)]) {
                    ans = a[t].r;
                    // cout << "HI" << a[t].r  << endl;
                    break;
                }
            }
            result[i][j] = ans;
        }
    }
    // for(int i = 0; i < 1 << k; i++) {
    //     for(int j = 0; j < 1 << k ;j++) {
    //         cout << result[i][j] << " \n"[j == (1 << k) - 1];
    //     }
    // }

    int a1 = 0;
    for(int i = 0; i < 1 << k; i++) if(result[i][i]) a1++;
    int a2 = 0;
    for(int i = 0; i < 1 << k; i++) {
        for(int j = 0; j < 1 << k; j++) {
            if(result[i][j] && result[j][i]) a2++;
        }
    }
    int a3 = 0;
    for(int i = 0; i < 1 << k; i++) {
        for(int j = 0; j < 1 << k; j++) {
            if(!result[i][j]) continue;
            for(int t = 0; t < 1 << k; t++) {
                a3 += result[j][t] && !result[i][t];
            }
        }
    }
    cout << a1 << " " << a2 << " " << a3 << endl;







}

int32_t main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int tt=1;
    //cin >> tt;
    while (tt--) 
    solve();
}

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

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

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

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

input:

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

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

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

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

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

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

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

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:

512 262144 134217728

result:

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