QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#430542#8770. ComparatorAfterlife#AC ✓76ms6444kbC++203.6kb2024-06-03 22:08:172024-06-03 22:08:17

Judging History

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

  • [2024-06-03 22:08:17]
  • 评测
  • 测评结果:AC
  • 用时:76ms
  • 内存:6444kb
  • [2024-06-03 22:08:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n , k;
char ope[1000005];
int top1;
bool num[1000005];
int top2;

int prio(char x) {
    if(x == '(' || x == ')') return 0;
    else if(x == '!') return 5;
    else if(x == '=') return 4;
    else if(x == '&') return 3;
    else if(x == '|') return 2;
    else if(x == '^') return 1;
    else return -1;
}
void pop_op() {
    char a = ope[top1] ; top1--;
    if(a == '!') {
        num[top2] ^= 1;
        return ;
    }
    int x = num[top2] , y = num[top2 - 1] ;
    top2 -= 2;
    int z;
    if(a == '=') z = (x == y) ;
    else if(a == '&') z = (x && y);
    else if(a == '|') z = (x || y);
    else if(a == '^') z = (x ^ y) ;
    else { printf("A %c\n",a) ; assert(0) ;}
    num[++top2] = z;
    return ;
}
bool evalu(const string& s,int vx,int vy) {
    top1 = top2 = 0;
    // cout << "EVA : " << vx <<' ' << vy << ' ' << s << ' ' ;
    for(int i = 0;i < s.size();i++) {
        // printf("OK %c\n",s[i]);
        if(prio(s[i]) >= 0) { ///符号
            if(s[i] == '(') {
                ope[++top1] = s[i] ; continue ;
            }
            else if(s[i] == ')') {
                while(ope[top1] != '(') pop_op() ;
                top1-- ; continue ;
            }
            while(top1 > 0 && (prio(ope[top1]) > prio(s[i])) || (ope[top1] == s[i] && s[i] != '!')) pop_op() ;
            ope[++top1] = s[i] ;
        }
        else {
            bool val;
            if(s[i] == '0') val = 0;
            else if(s[i] == '1') val = 1;
            else if(s[i] == 'x') val = vx;
            else if(s[i] == 'y') val = vy;
            else assert(0) ;

            num[++top2] = val;
        }
    }
    while(top1) pop_op() ;
    // cout << num[top2] << '\n';
    return num[top2] ;
}

int op[10][10][2][2] ;
vector<array<int,5> > vec;
bool f[1 << 10][1<< 10];
bitset<1024> c0[1<<10] , c1[1<<10];
int main() {
    ios::sync_with_stdio(false) ; cin.tie(0) ; 
    cin >> n >> k;
    memset(op,-1,sizeof(op)) ;
    for(int i = 1;i <= n;i++) {
        int u , v ;
        string s;
        int r;
        cin >> u >> v >> s >> r; u-- ; v--;
        for(int a = 0; a < 2;a++) {
            for(int b = 0;b < 2;b++) {
                if(op[u][v][a][b] != -1) continue ;
                if(evalu(s , a , b)) {
                    op[u][v][a][b] = 1;
                    vec.push_back({u,v,a,b,r}) ;
                }
            }
        }
    }
    int lst  ; cin >> lst;
    for(int i = 0;i < (1<<k);i++) {
        for(int j = 0;j < (1<<k);j++) {
            f[i][j] = lst;
            for(auto &p : vec) {
                if(((i >> p[0])&1) == p[2] && ((j >> p[1]) & 1) == p[3]) {
                    f[i][j] = p[4] ; break ;
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0;i < (1<<k);i++) {
        if(f[i][i]) ans++ ;
    }
    cout << ans <<' ' ; /// a0
    ans = 0;
    for(int i = 0;i < (1<<k);i++) {
        for(int j = 0;j < (1<<k);j++) {
            if(f[i][j] && f[j][i]) ans++ ;
        }
    }
    cout << ans <<' ' ; /// a1
    ans = 0;
    for(int i = 0;i < (1<<k);i++) {
        for(int j = 0;j < (1<<k);j++) {
            // r0[i][j] = f[i][j] ;
            // r1[i][j] = (1 ^ f[i][j]) ;
            c0[j][i] = f[i][j] ;
            c1[j][i] = (1 ^ f[i][j]) ;
        }
    }
    
    for(int i = 0;i < (1<<k);i++) {
        for(int j = 0;j < (1<<k);j++) {
            if(f[i][j]) {
                ans += (c0[i] & c1[j]).count() ;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5936kb

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

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

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

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

input:

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

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

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

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

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

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

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

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

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

input:

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

output:

1 1 0

result:

ok single line: '1 1 0'

Test #13:

score: 0
Accepted
time: 58ms
memory: 5764kb

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

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

input:

0 3
1

output:

8 64 0

result:

ok single line: '8 64 0'