QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#438910#8770. ComparatorZSH_ZSH#AC ✓146ms8072kbC++144.1kb2024-06-11 11:37:122024-06-11 11:37:13

Judging History

你现在查看的是最新测评结果

  • [2024-06-11 11:37:13]
  • 评测
  • 测评结果:AC
  • 用时:146ms
  • 内存:8072kb
  • [2024-06-11 11:37:12]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a);i<=(b);i++)
#define drep(i,a,b) for (int i=(a);i>=(b);i--)
typedef long long ll;
using namespace std;

#define fir first
#define sec second

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n,k; cin>>n>>k;
	vector<int> ret(4*k*k,-1);
	auto id=[&](int p,int x,int q,int y)
	{
		return (x*k+p)*(2*k)+(y*k+q); 
	};
	
	vector<array<int,4> > ord;
	rep(wtf,0,n-1)
	{
		int a,b,r;
		string s; 
		cin>>a>>b>>s>>r; a--,b--; 
		int len=s.size();
		
		vector<int> mat(len),stk;
		rep(i,0,len-1)
		{
			if (s[i]=='(') stk.push_back(i);
			else if (s[i]==')')
			{
				assert(stk.size());
				mat[stk.back()]=i;
				mat[i]=stk.back();
				stk.pop_back();
			}
			else mat[i]=i;
		}
		
		auto isop=[&](int p) -> int
		{
			char c=s[p];
			return c=='^'||c=='&'||c=='|'||c=='=';
		};
		auto dc=[&](auto &&self,int l,int r) -> array<int,4> // x*2+y
		{
			assert(l<=r);
			if (l==r)
			{
				char c=s[l];
				if (c=='0') return {0,0,0,0};
				if (c=='1') return {1,1,1,1};
				if (c=='x') return {0,0,1,1};
				if (c=='y') return {0,1,0,1};
				assert(0);
			}
			if (s[l]=='('&&mat[l]==r) return self(self,l+1,r-1);
			
			vector<array<int,4> > f;
			vector<char> op;
			for (int i=l;i<=r;i++)
			{
				if (s[i]=='!')
				{
					int j=i;
					while (j+1<=r&&s[j+1]=='!') j++;
					int c=(i-j+1)&1;
					f.push_back(self(self,j+1,mat[j+1]));
					if (c) rep(k,0,3) f.back()[k]^=1;
					i=mat[j+1];
					continue;
				}
				if (isop(i)) op.push_back(s[i]);
				else
				{
					f.push_back(self(self,i,mat[i]));
					i=mat[i];
				}
			}
			
			// =
			{
				assert(f.size()==op.size()+1);
				vector<array<int,4> > nf;
				vector<char> nop;
				nf.push_back(f[0]);
				f.erase(f.begin());
				rep(i,0,(int)f.size()-1)
				{
					if (op[i]=='=') rep(j,0,3) nf.back()[j]=(nf.back()[j]==f[i][j]);
					else nf.push_back(f[i]),nop.push_back(op[i]);
				}
				swap(f,nf);
				swap(op,nop); 
			}
			// &
			{
				assert(f.size()==op.size()+1);
				vector<array<int,4> > nf;
				vector<char> nop;
				nf.push_back(f[0]);
				f.erase(f.begin());
				rep(i,0,(int)f.size()-1)
				{
					if (op[i]=='&') rep(j,0,3) nf.back()[j]=(nf.back()[j]&f[i][j]);
					else nf.push_back(f[i]),nop.push_back(op[i]);
				}
				swap(f,nf);
				swap(op,nop);
			}
			// |
			{
				assert(f.size()==op.size()+1);
				vector<array<int,4> > nf;
				vector<char> nop;
				nf.push_back(f[0]);
				f.erase(f.begin());
				rep(i,0,(int)f.size()-1)
				{
					if (op[i]=='|') rep(j,0,3) nf.back()[j]=(nf.back()[j]|f[i][j]);
					else nf.push_back(f[i]),nop.push_back(op[i]);
				}
				swap(f,nf);
				swap(op,nop);
			}
			// ^
			{
				assert(f.size()==op.size()+1);
				vector<array<int,4> > nf;
				vector<char> nop;
				nf.push_back(f[0]);
				f.erase(f.begin());
				rep(i,0,(int)f.size()-1)
				{
					if (op[i]=='^') rep(j,0,3) nf.back()[j]=(nf.back()[j]^f[i][j]);
					else nf.push_back(f[i]),nop.push_back(op[i]);
				}
				swap(f,nf);
				swap(op,nop);
			}
			assert(f.size()==1);
			return f[0];
		};
		auto f=dc(dc,0,len-1);
		rep(s,0,3) if (f[s])
		{
			int i=s>>1,j=s&1,k=id(a,i,b,j);
			if (ret[k]!=-1) continue;
			ret[k]=r;
			ord.push_back({a,i,b,j});
		}
	}
	int bad; cin>>bad;
	
	vector<vector<int> > a(1<<k,vector<int>(k));
	rep(s,0,(1<<k)-1) rep(i,0,k-1) a[s][i]=(s>>i)&1;
	
	auto cmp=[&](int x,int y) -> int
	{	
		for (auto it:ord)
		{
			int i=it[0],p=it[1],j=it[2],q=it[3];
			if (a[x][i]==p&&a[y][j]==q) return ret[id(i,p,j,q)];
		}
		return bad;
	};
	vector<vector<int> > f(1<<k,vector<int>(1<<k));
	rep(i,0,(1<<k)-1) rep(j,0,(1<<k)-1) f[i][j]=cmp(i,j);
	
	vector<bitset<1<<10> > g(1<<k);
	rep(i,0,(1<<k)-1) rep(j,0,(1<<k)-1) if (f[i][j]) g[i][j]=1;
	
	int ans1=0,ans2=0;
	ll ans3=0;
	rep(i,0,(1<<k)-1) if (f[i][i]==1) ans1++;
	rep(i,0,(1<<k)-1) rep(j,0,(1<<k)-1) if (f[i][j]==1&&f[j][i]==1) ans2++;
	rep(i,0,(1<<k)-1) rep(j,0,(1<<k)-1) if (f[i][j]==1)
	{
		ans3+=(g[j]&(~g[i])).count();
	} 
	
	printf("%d %d %lld\n",ans1,ans2,ans3);
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3628kb

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: 0ms
memory: 3816kb

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: 47ms
memory: 3868kb

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: 146ms
memory: 7616kb

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: 4ms
memory: 8072kb

input:

1 3
1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3736kb

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: 3824kb

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: 3728kb

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: 3788kb

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: 9ms
memory: 7748kb

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: 3816kb

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: 2ms
memory: 4732kb

input:

1 1
1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

1 1 0

result:

ok single line: '1 1 0'

Test #13:

score: 0
Accepted
time: 116ms
memory: 7620kb

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: 3824kb

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: 4016kb

input:

0 3
1

output:

8 64 0

result:

ok single line: '8 64 0'