QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#592456 | #8770. Comparator | Forever_Young | AC ✓ | 224ms | 8728kb | C++23 | 2.8kb | 2024-09-26 22:40:31 | 2024-09-26 22:40:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define data dataa
#define rank rk
using LL=long long;
using ULL=unsigned long long;
using LD=long double;
char s[1000010],opt[1000010];
int num[1000010],res[11][11][2][2],tim[11][11][2][2],n,k,R;
bool f[1<<10][1<<10];
bitset<1024>g[1<<10],h[1<<10];
bool cal(bool x,char op,bool y)
{
if(op=='=')return x==y;
else if(op=='&')return x&y;
else if(op=='|')return x|y;
else if(op=='^')return x^y;
else assert(0);
}
int rank(char op)
{
if(op=='=')return 1;
else if(op=='&')return 2;
else if(op=='|')return 3;
else if(op=='^')return 4;
else assert(0);
}
bool cal(char s[],int x,int y)
{
int top1=0,top2=0,n=strlen(s+1);
rep(i,n)
if(s[i]=='(')opt[++top1]='(';
else if(s[i]==')')
{
for(;top1&&opt[top1]!='(';top1--,top2--)num[top2-1]=cal(num[top2-1],opt[top1],num[top2]);
assert(top1&&opt[top1]=='(');
top1--;
int now=num[top2--];
for(;top1&&opt[top1]=='!';now=!now,top1--);
num[++top2]=now;
}
else if(s[i]=='!')opt[++top1]='!';
else if(s[i]=='x'||s[i]=='y'||s[i]=='0'||s[i]=='1')
{
int now;
if(s[i]=='0'||s[i]=='1')now=s[i]-'0';
else if(s[i]=='x')now=x;
else now=y;
for(;top1&&opt[top1]=='!';now=!now,top1--);
num[++top2]=now;
}
else
{
for(;top1&&opt[top1]!='('&&rank(opt[top1])<=rank(s[i]);top1--,top2--)num[top2-1]=cal(num[top2-1],opt[top1],num[top2]);
opt[++top1]=s[i];
}
for(;top1;top1--,top2--)num[top2-1]=cal(num[top2-1],opt[top1],num[top2]);
assert(top2==1&&!top1);
return num[1];
}
bool cal(int x,int y)
{
int mn=n+1;
bool result=R;
rep(i,k)rep(j,k)
{
int b1=(x>>(i-1))&1,b2=(y>>(j-1))&1;
if(res[i][j][b1][b2]==-1||tim[i][j][b1][b2]>=mn)continue;
mn=tim[i][j][b1][b2];
result=res[i][j][b1][b2];
}
return result;
}
int main()
{
scanf("%d%d",&n,&k);
rep(i,k)rep(j,k)rep(b1,2)rep(b2,2)res[i][j][b1-1][b2-1]=-1;
rep(i,n)
{
int x,y,r;
scanf("%d%d%s%d",&x,&y,s+1,&r);
for(int j=0;j<2;j++)for(int k=0;k<2;k++)if(res[x][y][j][k]==-1&&cal(s,j,k))res[x][y][j][k]=r,tim[x][y][j][k]=i;
}
scanf("%d",&R);
for(int i=0;i<(1<<k);i++)for(int j=0;j<(1<<k);j++)f[i][j]=cal(i,j);
int ans1=0,ans2=0,ans3=0;
for(int i=0;i<(1<<k);i++)if(f[i][i])ans1++;
for(int i=0;i<(1<<k);i++)for(int j=0;j<(1<<k);j++)if(f[i][j]&&f[j][i])ans2++;
for(int i=0;i<(1<<k);i++)for(int j=0;j<(1<<k);j++)if(f[i][j])g[i].set(j);else h[i].set(j);
for(int i=0;i<(1<<k);i++)for(int j=0;j<(1<<k);j++)if(f[i][j])ans3+=(h[i]&g[j]).count();
printf("%d %d %d\n",ans1,ans2,ans3);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5872kb
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: 7892kb
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: 5896kb
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: 224ms
memory: 8380kb
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: 6952kb
input:
1 3 1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...
output:
4 16 0
result:
ok single line: '4 16 0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 5892kb
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: 7996kb
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: 7924kb
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: 7916kb
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: 115ms
memory: 8728kb
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: 5900kb
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: 3ms
memory: 7924kb
input:
1 1 1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
output:
1 1 0
result:
ok single line: '1 1 0'
Test #13:
score: 0
Accepted
time: 172ms
memory: 8356kb
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: 5880kb
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: 5884kb
input:
0 3 1
output:
8 64 0
result:
ok single line: '8 64 0'