QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#428126 | #8770. Comparator | ucup-team3510# | AC ✓ | 328ms | 36916kb | C++14 | 3.0kb | 2024-06-01 17:37:19 | 2024-06-01 17:37:19 |
Judging History
answer
#include<iostream>
#include<bitset>
#include<cstring>
using namespace std;
int p[1000010];
char s[1000010];
int solve(int l,int r,int op=0)
{
while(p[r]==l)
{
l++,r--,op=0;
}
if(op==0)
{
for(int i=r;i>=l;i--)
{
if(s[i]==')')
{
i=p[i];
continue;
}
if(s[i]=='^')
{
return solve(l,i-1,0)^solve(i+1,r,1);
}
}
}
if(op<=1)
{
for(int i=r;i>=l;i--)
{
if(s[i]==')')
{
i=p[i];
continue;
}
if(s[i]=='|')
{
return solve(l,i-1,0)|solve(i+1,r,2);
}
}
}
if(op<=2)
{
for(int i=r;i>=l;i--)
{
if(s[i]==')')
{
i=p[i];
continue;
}
if(s[i]=='&')
{
return solve(l,i-1,0)&solve(i+1,r,3);
}
}
}
if(op<=3)
{
for(int i=r;i>=l;i--)
{
if(s[i]==')')
{
i=p[i];
continue;
}
if(s[i]=='=')
{
int L=solve(l,i-1,0);
int R=solve(i+1,r,4);
return (L&R)|((15^L)&(15^R));
}
}
}
if(s[l]=='!')
{
return 15^solve(l+1,r,4);
}
if(s[l]=='0')
{
return 0;
}
if(s[l]=='1')
{
return 15;
}
if(s[l]=='x')
{
return 12;
}
return 10;
}
inline void work(int n)
{
static int sta[500010];
int head=0;
for(int i=1;i<=n;i++)
{
if(s[i]=='(')
{
sta[++head]=i;
}
if(s[i]==')')
{
p[i]=sta[head--];
}
}
}
struct expr
{
int x,y,f;
bool ret;
};
int n,m;
expr a[200010];
bool f[1<<10][1<<10];
bitset<1<<10> F[1<<10];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i].x>>a[i].y>>s+1>>a[i].ret;
a[i].x--,a[i].y--;
int len=strlen(s+1);
work(len),a[i].f=solve(1,len);
}
bool ret;
cin>>ret;
a[++n]={0,0,15,ret};
int U=(1<<m)-1;
for(int i=0;i<=U;i++)
{
int S=U,S0=U,S1=U;
for(int j=1;j<=n;j++)
{
int t=(i&(1<<a[j].x))?
(a[j].f>>2):(a[j].f&3);
if((S0&(1<<a[j].y))&&(t&1))
{
if(a[j].ret)
{
int tS=S&(U^(1<<a[j].y));
int s=(S1^tS)&(U^(1<<a[j].y));
for(int k=tS;k;k=k-1&tS)
{
f[i][s|k]=1;
}
f[i][s]=1;
if(S==tS)
{
break;
}
S0^=1<<a[j].y,S=tS;
}
else
{
if(!(S&(1<<a[j].y)))
{
break;
}
S0^=1<<a[j].y;
S^=1<<a[j].y;
}
}
if((S1&(1<<a[j].y))&&(t&2))
{
if(a[j].ret)
{
int tS=S&(U^(1<<a[j].y));
int s=S1^tS;
for(int k=tS;k;k=k-1&tS)
{
f[i][s|k]=1;
}
f[i][s]=1;
if(S==tS)
{
break;
}
S1^=1<<a[j].y,S=tS;
}
else
{
if(!(S&(1<<a[j].y)))
{
break;
}
S1^=1<<a[j].y;
S^=1<<a[j].y;
}
}
}
}
int ans1=0,ans2=0,ans3=0;
for(int i=0;i<(1<<m);i++)
{
ans1+=f[i][i];
for(int j=0;j<(1<<m);j++)
{
ans2+=f[i][j]&&f[j][i];
F[i][j]=f[i][j];
}
}
for(int i=0;i<(1<<m);i++)
{
for(int j=0;j<(1<<m);j++)
{
if(f[i][j])
{
ans3+=(F[j]&(~F[i])).count();
}
}
}
cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7648kb
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: 2ms
memory: 11968kb
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: 16ms
memory: 9984kb
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: 92ms
memory: 10528kb
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: 15ms
memory: 36916kb
input:
1 3 1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...
output:
4 16 0
result:
ok single line: '4 16 0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 7588kb
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: 5596kb
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: 1ms
memory: 5600kb
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: 1ms
memory: 7640kb
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: 6ms
memory: 9860kb
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: 5892kb
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: 1ms
memory: 9692kb
input:
1 1 1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
output:
1 1 0
result:
ok single line: '1 1 0'
Test #13:
score: 0
Accepted
time: 328ms
memory: 8424kb
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: 9812kb
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: 7644kb
input:
0 3 1
output:
8 64 0
result:
ok single line: '8 64 0'