QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#427757 | #8770. Comparator | ucup-team3586# | AC ✓ | 140ms | 138952kb | C++23 | 4.4kb | 2024-06-01 15:28:22 | 2024-06-01 15:28:23 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int n,k;
int a[200200],b[200200],val[200200];
string s[200200];
vector<vector<int>> table[200200];
string S;
int depth[1001000],len;
vector<int> op[1001000][5];
string Seq="!=&|^";
int Order[512];
vector<vector<int>> One={{1,1},{1,1}};
vector<vector<int>> Zero={{0,0},{0,0}};
vector<vector<int>> X={{0,0},{1,1}};
vector<vector<int>> Y={{0,1},{0,1}};
vector<vector<int>> Not(vector<vector<int>> Table)
{
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
Table[i][j]^=1;
return Table;
}
vector<vector<int>> Equal(vector<vector<int>> a,vector<vector<int>> b)
{
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
a[i][j]=(a[i][j]==b[i][j]);
return a;
}
vector<vector<int>> And(vector<vector<int>> a,vector<vector<int>> b)
{
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
a[i][j]=(a[i][j]&b[i][j]);
return a;
}
vector<vector<int>> Or(vector<vector<int>> a,vector<vector<int>> b)
{
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
a[i][j]=(a[i][j]|b[i][j]);
return a;
}
vector<vector<int>> Xor(vector<vector<int>> a,vector<vector<int>> b)
{
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
a[i][j]=(a[i][j]^b[i][j]);
return a;
}
vector<vector<int>> solve(int l,int r)
{
if(l==r)
{
if(S[l]=='0') return Zero;
if(S[l]=='1') return One;
if(S[l]=='x') return X;
if(S[l]=='y') return Y;
assert(0);
}
for(int i=4;i>=0;i--)
{
int p1=lb(op[depth[l]][i],l);
int p2=ub(op[depth[l]][i],r);
if(p1!=p2)
{
int pos=(i?op[depth[l]][i][p2-1]:op[depth[l]][i][p1]);
if(i==0)
return Not(solve(pos+1,r));
if(i==1)
return Equal(solve(l,pos-1),solve(pos+1,r));
if(i==2)
return And(solve(l,pos-1),solve(pos+1,r));
if(i==3)
return Or(solve(l,pos-1),solve(pos+1,r));
if(i==4)
return Xor(solve(l,pos-1),solve(pos+1,r));
assert(0);
}
}
assert(S[l]=='('&&S[r]==')');
return solve(l+1,r-1);
}
vector<vector<int>> gen(string str)
{
S=str;
len=sz(S);
for(int i=0;i<len;i++)
depth[i+1]=depth[i]+(S[i]=='(')-(S[i]==')');
int d=*max_element(depth,depth+len+1);
for(int i=0;i<=d;i++)
for(int j=0;j<5;j++)
op[i][j].clear();
for(int i=0;i<len;i++)
if(S[i]!='('&&S[i]!=')'&&S[i]!='x'&&S[i]!='y'&&S[i]!='0'&&S[i]!='1')
op[depth[i]][Order[S[i]]].pb(i);
return solve(0,len-1);
}
vector<vector<int>> nTable[304];
int nA[304],nB[304],ind,nVal[304];
int Return;
int Mask[12][12];
int Result[1<<10][1<<10];
bitset<1024> W[1<<10],L[1<<10];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for(int i=0;i<5;i++)
Order[Seq[i]]=i;
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>a[i]>>b[i]>>s[i]>>val[i];
cin>>Return;
for(int i=1;i<=n;i++)
table[i]=gen(s[i]);
for(int i=1;i<=n;i++)
{
int msk=0;
for(int x=0;x<2;x++)
for(int y=0;y<2;y++)
msk|=(table[i][x][y]<<(x+x+y));
int val=Mask[a[i]][b[i]];
if((val&msk)==msk) continue;
ind++;
nA[ind]=a[i]-1;
nB[ind]=b[i]-1;
nTable[ind]=table[i];
nVal[ind]=::val[i];
Mask[a[i]][b[i]]|=msk;
if((val|msk)==15) break;
}
for(int i=0;i<1<<k;i++)
for(int j=0;j<1<<k;j++)
{
bool ok=false;
for(int p=1;p<=ind;p++)
{
int x=(i>>nA[p]&1);
int y=(j>>nB[p]&1);
if(nTable[p][x][y])
{
ok=true;
Result[i][j]=nVal[p];
break;
}
}
if(!ok)
Result[i][j]=Return;
}
int Ans1=0,Ans2=0,Ans3=0;
for(int i=0;i<1<<k;i++)
for(int j=0;j<1<<k;j++)
if(Result[i][j])
W[i][j]=1;
else
L[i][j]=1;
for(int i=0;i<1<<k;i++)
if(Result[i][i])
Ans1++;
for(int i=0;i<1<<k;i++)
for(int j=0;j<1<<k;j++)
if(Result[i][j]&&Result[j][i])
Ans2++;
for(int i=0;i<1<<k;i++)
for(int j=0;j<1<<k;j++)
if(Result[i][j])
Ans3+=(W[j]&L[i]).count();
cout<<Ans1<<" "<<Ans2<<" "<<Ans3<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 13840kb
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: 4ms
memory: 13856kb
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: 84ms
memory: 15452kb
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: 140ms
memory: 44088kb
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: 105ms
memory: 138952kb
input:
1 3 1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...
output:
4 16 0
result:
ok single line: '4 16 0'
Test #6:
score: 0
Accepted
time: 4ms
memory: 14120kb
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: 7ms
memory: 13804kb
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: 7ms
memory: 13796kb
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: 3ms
memory: 14100kb
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: 25ms
memory: 18564kb
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: 4ms
memory: 14076kb
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: 27404kb
input:
1 1 1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
output:
1 1 0
result:
ok single line: '1 1 0'
Test #13:
score: 0
Accepted
time: 92ms
memory: 46504kb
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: 8ms
memory: 13848kb
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: 3ms
memory: 13836kb
input:
0 3 1
output:
8 64 0
result:
ok single line: '8 64 0'