QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#465470#8770. Comparatorucup-team1525AC ✓256ms23480kbC++174.7kb2024-07-06 22:33:342024-07-06 22:33:34

Judging History

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

  • [2024-07-06 22:33:34]
  • 评测
  • 测评结果:AC
  • 用时:256ms
  • 内存:23480kb
  • [2024-07-06 22:33:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int len;
const int M=11;
int n,m;
int ed[M][M][4],val[M][M][4];
int f[1200][1200];
const int N=1000005;
char expr[N];
int pos;
int x,y;
int fin;
// bool expression();
bool variable();
bool expeq();
bool expand();
bool expor();
bool expxor();
bool term()
{
    if (expr[pos]=='(')
    {
        ++pos;
        // bool ans=expression();
        bool ans=expxor();
        ++pos;
        return ans;
    }
    else 
        if (expr[pos] == '!') 
        {
            ++pos;
            return !term();
        }
        else
            return variable();
}
bool calc(bool x,bool y,char z)
{
    switch (z)
    {
        case '|':return x|y;
        case '&':return x&y;
        case '=':return x==y;
        case '^':return x^y;
    }
    return 0;
}
// bool expeq() 
// {
//     bool ans = expand();
//     while (pos <len && expr[pos] == '=') 
//     {
//         ++pos;
//         bool tmp = expand();
//         ans = (ans == tmp);
//     }
//     return ans;
// }

// bool expand() 
// {
//     bool ans = expor();
//     while (pos <len && expr[pos] == '&') 
//     {
//         ++pos;
//         bool tmp = expor();
//         ans = (ans & tmp);
//     }
//     return ans;
// }

// bool expor()
// {
//     bool ans = expxor();
//     while (pos <len && expr[pos] == '|') 
//     {
//         ++pos;
//         bool tmp = expxor();
//         ans = (ans | tmp);
//     }
//     return ans;
// }
// bool expxor()
// {
//     bool ans = term();
//     while (pos <len && expr[pos] == '^') 
//     {
//         ++pos;
//         bool tmp = term();
//         ans = (ans ^ tmp);
//     }
//     return ans;
// }
bool expeq() 
{
    bool ans = term();
    while (pos <len && expr[pos] == '=') 
    {
        ++pos;
        bool tmp = term();
        ans = (ans == tmp);
    }
    return ans;
}

bool expand() 
{
    bool ans = expeq();
    while (pos <len && expr[pos] == '&') 
    {
        ++pos;
        bool tmp = expeq();
        ans = (ans & tmp);
    }
    return ans;
}

bool expor()
{
    bool ans = expand();
    while (pos <len && expr[pos] == '|') 
    {
        ++pos;
        bool tmp = expand();
        ans = (ans | tmp);
    }
    return ans;
}
bool expxor()
{
    bool ans = expor();
    while (pos <len && expr[pos] == '^') 
    {
        ++pos;
        bool tmp = expor();
        ans = (ans ^ tmp);
    }
    return ans;
}
// bool expression()
// {
//     bool ans=term();
//     while (pos<len)
//     {
//         char opt=expr[pos];
//         if (opt=='|'||opt=='&'||opt=='='||opt=='^')
//         {
//             ++pos;
//             bool tmp=term();
//             ans=calc(ans,tmp,opt);
//         }
//         else
//             break;
//     }
//     return ans;
// }
bool variable()
{
    bool ans=0;
    switch (expr[pos])
    {
        case '0':ans=0;break;
        case '1':ans=1;break;
        case 'x':ans=x;break;
        case 'y':ans=y;break;
    }
    ++pos;
    return ans;
}
void work(int id)
{
    int u,v,w;
    scanf("%d%d%s%d",&u,&v,expr,&w);
    --u;
    --v;
    len=strlen(expr);
    for (int i=0;i<=3;++i)
        {
            if (ed[u][v][i]!=0)
                continue;
            x=i/2;
            y=i&1;
            pos=0;
            // bool ans=expression();
            bool ans=expxor();
            if (ans)
            {
                ed[u][v][i]=id;
                val[u][v][i]=w;
            }
        }
}
int work(int x,int y)
{
    int t=n+1,v=fin;
    for (int i=0;i<m;++i)
        for (int j=0;j<m;++j)
        {
            int p=(x>>i)&1,q=(y>>j)&1;
            int o=p*2+q;
            if (ed[i][j][o]!=0&&ed[i][j][o]<t)
            {
                t=ed[i][j][o];
                v=val[i][j][o];
            }
        }
    return v;
}

bitset<1030> g[N+5];
int main()
{
    // freopen("c.in","r",stdin);
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;++i)
        work(i);
    scanf("%d",&fin);
    for (int i=0;i<(1<<m);++i)
        for (int j=0;j<(1<<m);++j){
            f[i][j]=work(i,j);
            if(f[i][j]) g[i][j]=1;
        }
    //  for (int i=0;i<(1<<m);++i,puts(""))
    //     for (int j=0;j<(1<<m);++j)
    //         printf("%d ",f[i][j]);
    int s1=0,s2=0,s3=0;
    for(int i=0;i<(1<<m);i++){
        if(g[i][i]) s1++;
        for(int j=0;j<(1<<m);j++)
            if(g[i][j]&&g[j][i]) s2++;
    }
    for(int i=0;i<(1<<m);i++){
        for(int j=0;j<(1<<m);j++)
            if(g[i][j])
                s3+=g[j].count()-(g[i]&g[j]).count();
    }
    printf("%d %d %d\n",s1,s2,s3);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

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

input:

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

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

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

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

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

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

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

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

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

input:

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

output:

1 1 0

result:

ok single line: '1 1 0'

Test #13:

score: 0
Accepted
time: 187ms
memory: 10572kb

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

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

input:

0 3
1

output:

8 64 0

result:

ok single line: '8 64 0'