QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#456421#8770. Comparatorucup-team2307#AC ✓180ms18340kbC++203.8kb2024-06-27 21:59:042024-06-27 21:59:05

Judging History

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

  • [2024-06-27 21:59:05]
  • 评测
  • 测评结果:AC
  • 用时:180ms
  • 内存:18340kb
  • [2024-06-27 21:59:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
//#define int ll
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pii = pair<int, int>;
using vi = vector<int>;
#define fi first
#define se second
#define pb push_back

using row=array<bool,2>;
using table=array<row,2>;

struct Parser
{
    string s;
    bool x,y;
    int ind=0;
    char cur()
    {
        if(ind==s.size()) return ')';
        else return s[ind];
    }
    char next()
    {
        if(ind==s.size()) return ')';
        else return s[ind++];
    }
    bool par_expr()
    {
        switch(next())
        {
            case '0': return 0;
            case '1': return 1;
            case 'x': return x;
            case 'y': return y;
            case '(': {
                bool res = xor_expr();
                assert(next() == ')');
                return res;
            }
            case '!': return !par_expr();
            default:
                assert(false);
        }
    }
    bool xor_expr()
    {
        int res=or_expr();
        while(cur()=='^') next(),res^=or_expr();
        return res;
    }
    bool or_expr()
    {
        int res=and_expr();
        while(cur()=='|') next(),res|=and_expr();
        return res;
    }
    bool and_expr()
    {
        int res=eq_expr();
        while(cur()=='&') next(),res&=eq_expr();
        return res;
    }
    bool eq_expr()
    {
        int res=par_expr();
        while(cur()=='=') next(),res=res==par_expr();
        return res;
    }
};

table read()
{
    string s;
    cin>>s;
    table res= {
        row{Parser{s,0,0}.xor_expr(),Parser{s,0,1}.xor_expr()},
        row{Parser{s,1,0}.xor_expr(),Parser{s,1,1}.xor_expr()}
    };
//    cout<<s<<" -> "<<res[0][0]<<res[0][1]<<res[1][0]<<res[1][1]<<"\n";
    return res;
}

const int N=1<<10;

int dp[1111][1111];
bool killed[10][10][2][2];
vector<int> setter[10][2];

bitset<N> lr[N];

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    int n, k;
    cin>>n>>k;
    for (int i=0; i<k; i++)
        for (int j=0; j<k; j++)
            for (int x=0; x<2; x++)
                for (int y=0; y<2; y++)
                    killed[i][j][x][y] = false;
    for (int i=0; i<(1<<k); i++)
        for (int j=0; j<(1<<k); j++)
            dp[i][j] = -1;
    for (int i=0; i<(1<<k); i++)
        for (int j=0; j<k; j++)
            setter[j][(i>>j)&1].pb(i);

    while (n--)
    {
        int x, y, val;
        cin>>x>>y;
        x--;y--;
        auto res = read();
        cin>>val;

        for (int i=0; i<2; i++)
            for (int j=0; j<2; j++)
                if (res[i][j])
                    if (!killed[x][y][i][j])
                    {
                        killed[x][y][i][j] = true;
                        for (int a : setter[x][i])
                            for (int b : setter[y][j])
                                if (dp[a][b] == -1)
                                    dp[a][b] = val;
                    }
    }
    int val;
    cin>>val;
    n = 1<<k;
    for (int a=0; a<n; a++)
        for (int b=0; b<n; b++)
            if (dp[a][b] == -1)
                dp[a][b] = val;

    int r=0, s=0, t=0;
    for (int i=0; i<n; i++)
        if (dp[i][i] == 1) r++;
    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++)
            if (dp[i][j] * dp[j][i] == 1) s++;

    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            lr[i][j]=dp[i][j];
    for(int x=0;x<n;x++)
        for(int y=0;y<n;y++)
            if(dp[x][y])
                t+=(lr[y]&~lr[x]).count();

//    for (int i=0; i<n; i++, cout<<"\n")
//        for (int j=0; j<n; j++)
//            cout<<dp[i][j]<<" ";



    cout<<r<<" "<<s<<" "<<t<<"\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

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

input:

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

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

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

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

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

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

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

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

input:

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

output:

1 1 0

result:

ok single line: '1 1 0'

Test #13:

score: 0
Accepted
time: 63ms
memory: 8160kb

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

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

input:

0 3
1

output:

8 64 0

result:

ok single line: '8 64 0'