QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#438904#8770. ComparatorZSH_ZSH#WA 106ms8060kbC++142.6kb2024-06-11 11:18:432024-06-11 11:18:43

Judging History

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

  • [2024-06-11 11:18:43]
  • 评测
  • 测评结果:WA
  • 用时:106ms
  • 内存:8060kb
  • [2024-06-11 11:18:43]
  • 提交

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[r]==')')
			{
				int m=mat[r];
				if (m==l) return self(self,l+1,r-1);
			}
			auto rs=self(self,mat[r],r);
			int p=mat[r]-1;
			while (p>=l&&s[p]=='!')
			{
				rep(i,0,3) rs[i]^=1;
				p--;
			}
			if (p==l-1) return rs;
			auto ls=self(self,l,p-1);
			assert(isop(p));
			rep(i,0,3) 
			{
				if (s[p]=='^') ls[i]^=rs[i];
				if (s[p]=='&') ls[i]&=rs[i];
				if (s[p]=='|') ls[i]|=rs[i];
				if (s[p]=='=') ls[i]=(ls[i]==rs[i]);
			}
			return ls; 
		};
		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: 4036kb

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

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: 17ms
memory: 3852kb

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

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

input:

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

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3748kb

input:

1 1
1 1 x^y|1 0
1

output:

0 0 0

result:

wrong answer 1st lines differ - expected: '1 1 0', found: '0 0 0'