QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#429458 | #8770. Comparator | Lynkcat | AC ✓ | 2101ms | 26600kb | C++20 | 5.1kb | 2024-06-02 15:38:21 | 2024-06-02 15:38:21 |
Judging History
answer
#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
#define sz(x) ((int)((x).size()))
// #define int ll
// #define N
using namespace std;
const int N=200005,M=1024;
int a[N],b[N],c[N];
bool bl[N][2][2];
bitset<M>f[M];
int n,m;
int rl[M],tmp[M];
int vis[M][M];
int lst[N][10][2];
void dfs(int x,int k)
{
if (k>n||rl[b[k]]!=2)
{
int u=0,ad=0;
for (int i=0;i<m;i++)
if (rl[i]==2) u|=(1<<i);
else ad|=(rl[i]<<i);
for (int i=u;;i=(i-1)&u)
{
int v=(ad|i);
vis[x][v]=1;
// cout<<x<<","<<v<<" "<<k<<" "<<c[k]<<endl;
f[x][v]=c[k];
if (!i) break;
}
return;
}
for (rl[b[k]]=0;rl[b[k]]<2;rl[b[k]]++)
{
if (bl[k][(x>>a[k])&1][rl[b[k]]])
{
int u=0,ad=0;
for (int i=0;i<m;i++)
if (rl[i]==2) u|=(1<<i);
else ad|=(rl[i]<<i);
for (int i=u;;i=(i-1)&u)
{
int v=(ad|i);
vis[x][v]=1;
// if (x==v)
// cout<<x<<","<<v<<" "<<k<<" "<<c[k]<<endl;
f[x][v]=c[k];
if (!i) break;
}
} else
{
int op=tmp[b[k]];
tmp[b[k]]=lst[k][b[k]][rl[b[k]]];
int nxt=n+1;
for (int i=0;i<m;i++) nxt=min(nxt,tmp[i]);
dfs(x,nxt);
tmp[b[k]]=op;
}
}
rl[b[k]]=2;
}
inline int calc(int x,int y,char c)
{
if (c=='=') return (x==y);
if (c=='&') return (x&y);
if (c=='|') return (x|y);
return (x^y);
}
int getv(string &st,int l,int r,int x,int y)
{
vector<char>s;
vector<int>t;
for (int i=0;i<sz(st);i++)
{
if (st[i]=='(')
{
s.push_back('(');
}
else
if (st[i]==')')
{
while (s.back()!='(')
{
int a=t[sz(t)-2],b=t[sz(t)-1];
t.pop_back();
t.pop_back();
t.push_back(calc(a,b,s.back()));
s.pop_back();
}
s.pop_back();
} else
if (st[i]=='^')
{
while (s.back()=='='||s.back()=='|'||s.back()=='^'||s.back()=='&')
{
int a=t[sz(t)-2],b=t[sz(t)-1];
t.pop_back();
t.pop_back();
t.push_back(calc(a,b,s.back()));
s.pop_back();
}
s.push_back(st[i]);
} else
if (st[i]=='|')
{
while (s.back()=='='||s.back()=='&'||s.back()=='|')
{
int a=t[sz(t)-2],b=t[sz(t)-1];
t.pop_back();
t.pop_back();
t.push_back(calc(a,b,s.back()));
s.pop_back();
}
s.push_back(st[i]);
} else
if (st[i]=='&')
{
while (s.back()=='&'||s.back()=='=')
{
int a=t[sz(t)-2],b=t[sz(t)-1];
t.pop_back();
t.pop_back();
t.push_back(calc(a,b,s.back()));
s.pop_back();
}
s.push_back(st[i]);
} else
if (st[i]=='=')
{
while (s.back()=='=')
{
int a=t[sz(t)-2],b=t[sz(t)-1];
t.pop_back();
t.pop_back();
t.push_back(calc(a,b,s.back()));
s.pop_back();
}
s.push_back(st[i]);
} else
if (st[i]=='!')
{
s.push_back(st[i]);
continue;
} else
if (st[i]=='x')
{
t.push_back(x);
} else
if (st[i]=='y')
{
t.push_back(y);
} else t.push_back(st[i]-'0');
// cout<<"??"<<st[i]<<" "<<i<<" "<<sz(st)<<endl;
// for (auto u:s) cout<<u;cout<<endl;
// for (auto u:t) cout<<u;cout<<endl;
// cout<<endl;
while (s.size()&&s.back()=='!')
{
t.back()^=1;
s.pop_back();
}
// cout<<"??"<<st[i]<<" "<<i<<" "<<sz(st)<<endl;
// for (auto u:s) cout<<u;cout<<endl;
// for (auto u:t) cout<<u;cout<<endl;
// cout<<endl;
}
return t[0];
}
int bfs(int x,int y,int k)
{
if (k>n||bl[k][(x>>a[k])&1][(y>>b[k])&1])
{
return c[k];
}
return bfs(x,y,k+1);
}
void BellaKira()
{
cin>>n>>m;
for (int i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
string st;
cin>>st;
st='('+st+')';
cin>>c[i];
a[i]--,b[i]--;
for (int x=0;x<2;x++)
for (int y=0;y<2;y++)
{
int v=getv(st,0,sz(st)-1,x,y);
bl[i][x][y]=v;
// cout<<i<<","<<x<<" "<<y<<" -> "<<v<<endl;
}
}
cin>>c[n+1];
for (int u=0;u<(1<<m);u++)
{
for (int j=0;j<m;j++)
lst[n+1][j][0]=lst[n+1][j][1]=n+1;
for (int i=n;i>=1;i--)
{
memcpy(lst[i],lst[i+1],sizeof(lst[i]));
for (int x=0;x<2;x++)
if (bl[i][((u>>a[i])&1)][x])
{
lst[i][b[i]][x]=i;
}
}
for (int j=0;j<m;j++)
{
rl[j]=2;
tmp[j]=min(lst[1][j][0],lst[1][j][1]);
}
dfs(u,1);
}
int ans=0,ans1=0,ans2=0;
// for (int i=0;i<(1<<m);i++)
// for (int j=0;j<(1<<m);j++) assert(vis[i][j]);
for (int i=0;i<(1<<m);i++)
{
ans+=(f[i][i]==1);
}
// for (int i=0;i<(1<<m);i++)
// for (int j=0;j<(1<<m);j++) assert(bfs(i,j,1)==f[i][j]);
for (int i=0;i<(1<<m);i++)
for (int j=0;j<(1<<m);j++)
if (f[i][j]==1&&f[j][i]==1)
{
ans1++;
}
for (int i=0;i<(1<<m);i++)
for (int j=0;j<(1<<m);j++)
if (f[i][j]==1)
{
bitset<M>now=f[i];
now.flip();
now&=f[j];
ans2+=now.count();
}
cout<<ans<<" "<<ans1<<" "<<ans2<<endl;
}
signed main()
{
IOS;
cin.tie(0);
int T=1;
while (T--)
{
BellaKira();
}
}
/*list:
1.mod 998244353 or 1e9+7 or ???
2.N
3.duipai shuju xingtai duoyidian
...
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9736kb
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: 9732kb
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: 33ms
memory: 7844kb
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: 2101ms
memory: 26492kb
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: 18ms
memory: 10364kb
input:
1 3 1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...
output:
4 16 0
result:
ok single line: '4 16 0'
Test #6:
score: 0
Accepted
time: 1ms
memory: 9764kb
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: 7716kb
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: 10028kb
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: 7688kb
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: 8ms
memory: 11976kb
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: 9808kb
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: 0ms
memory: 10260kb
input:
1 1 1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
output:
1 1 0
result:
ok single line: '1 1 0'
Test #13:
score: 0
Accepted
time: 1328ms
memory: 26600kb
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: 7792kb
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: 7680kb
input:
0 3 1
output:
8 64 0
result:
ok single line: '8 64 0'