QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#662801 | #8770. Comparator | YMH_fourteen | AC ✓ | 106ms | 129308kb | C++14 | 2.7kb | 2024-10-21 10:38:58 | 2024-10-21 10:38:59 |
Judging History
answer
// Author: YE Minghan
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "templates/debug.h"
#else
#define dbg(...) (void)0
#define msg(...) (void)0
#endif
#define ll long long
#define endl '\n'
#define PB emplace_back
#define PPB pop_back
#define MP make_pair
#define ALL(Name) Name.begin(),Name.end()
#define PII pair<int,int>
#define VI vector<int>
#define GI greater<int>
#define fi first
#define se second
const int K=10,D=500005;
bool vis[K][K][2][2];
vector<tuple<int,int,bool,bool,bool>>vs;
int lst;
bitset<1<<K> f[1<<K];
int q,k;
int ans1,ans2,ans3;
int wx,wy,wv;
string S;
namespace EVAL
{
VI eq[D],xr[D],ad[D],os[D];
void init()
{
int mxd=0,cd=0;
for(char i:S)
{
cd+=(i=='(')-(i==')');
mxd=max(mxd,cd);
}
fill(eq,eq+mxd+1,VI());
fill(xr,xr+mxd+1,VI());
fill(ad,ad+mxd+1,VI());
fill(os,os+mxd+1,VI());
assert(!cd);
for(int i=0;i<S.size();i++)
{
cd+=(S[i]=='(')-(S[i]==')');
if(S[i]=='=')eq[cd].PB(i);
if(S[i]=='&')ad[cd].PB(i);
if(S[i]=='|')os[cd].PB(i);
if(S[i]=='^')xr[cd].PB(i);
}
}
int eval(int L,int R,int d)
{
if(L==R)
{
if(S[L]=='0')return 0;
if(S[L]=='1')return 15;
if(S[L]=='x')return 12;
if(S[L]=='y')return 10;
assert(0);
}
auto it=eq[0].begin();
if((it=lower_bound(ALL(xr[d]),L))!=xr[d].end()&&*it<=R)
return eval(L,*it-1,d)^eval(*it+1,R,d);
if((it=lower_bound(ALL(os[d]),L))!=os[d].end()&&*it<=R)
return eval(L,*it-1,d)|eval(*it+1,R,d);
if((it=lower_bound(ALL(ad[d]),L))!=ad[d].end()&&*it<=R)
return eval(L,*it-1,d)&eval(*it+1,R,d);
if((it=lower_bound(ALL(eq[d]),L))!=eq[d].end()&&*it<=R)
return 15^eval(L,*it-1,d)^eval(*it+1,R,d);
if(S[L]=='!')return 15^eval(L+1,R,d);
if(S[L]=='('&&S[R]==')')return eval(L+1,R-1,d+1);
assert(0);
}
// 11,10,01,00
int ev(){init();return eval(0,S.size()-1,0);}
}
int main()
{
ios::sync_with_stdio(false),cin.tie(nullptr);
// int _;cin>>_;while(_--)
cin>>q>>k;
while(q--)
{
cin>>wx>>wy>>S>>wv;
int vl=EVAL::ev();
wx--,wy--;
for(int i=0;i<=1;i++)
for(int j=0;j<=1;j++)
if(!vis[wx][wy][i][j]&&((vl>>(2*i+j))&1))
vs.PB(wx,wy,i,j,wv),vis[wx][wy][i][j]=1;
}
cin>>lst;
for(int i=0;i<1<<k;i++)
for(int j=0;j<1<<k;j++)
{
bool ok=0;
for(auto [x,y,s,t,v]:vs)
if(((i>>x)&1)==s&&((j>>y)&1)==t)
{
f[i][j]=v;
ok=1;
break;
}
if(!ok)f[i][j]=lst;
}
for(int i=0;i<1<<k;i++)ans1+=f[i][i];
for(int i=0;i<1<<k;i++)
for(int j=0;j<1<<k;j++)ans2+=f[i][j]&&f[j][i];
for(int i=0;i<1<<k;i++)
for(int j=0;j<1<<k;j++)
if(f[i][j])ans3+=(f[j]&~f[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: 3ms
memory: 50524kb
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: 8ms
memory: 50512kb
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: 44ms
memory: 50544kb
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: 106ms
memory: 50608kb
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: 20ms
memory: 129308kb
input:
1 3 1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...
output:
4 16 0
result:
ok single line: '4 16 0'
Test #6:
score: 0
Accepted
time: 8ms
memory: 50728kb
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: 9ms
memory: 50724kb
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: 8ms
memory: 50408kb
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: 8ms
memory: 50516kb
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: 16ms
memory: 50828kb
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: 6ms
memory: 50520kb
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: 5ms
memory: 50656kb
input:
1 1 1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
output:
1 1 0
result:
ok single line: '1 1 0'
Test #13:
score: 0
Accepted
time: 71ms
memory: 50648kb
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: 4ms
memory: 50684kb
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: 50476kb
input:
0 3 1
output:
8 64 0
result:
ok single line: '8 64 0'