为什么85pt?怎么改?(小图灵55pt)
查看原帖
为什么85pt?怎么改?(小图灵55pt)
501947
DengDuck鄧德楼主2022/10/30 19:01

#include<bits/stdc++.h>
using namespace std;
long long n,a,b,p[1000005];
char c[1000005];
stack<long long>s;
bool dfs(long long l,long long r)
{

	if(c[l]=='('&&c[r]==')'&&p[l]==r)
	{
		l++;
		r--;
	}	
	if(l==r)
	{
		if(c[l]=='0')return 0;
		return 1;
	}
	for(int i=r;i>=l;i--)
	{
		if(c[i]==')')
		{
			i=p[i];
		}
		if(c[i]=='|')
		{
			bool x=dfs(l,i-1);
			if(x)
			{
			//	cout<<l<<' '<<i-1<<'|'<<i+1<<' '<<r<<endl;
				a++;
				return 1;
			}
			else{
				bool y=dfs(i+1,r);
				if(y)
				{
					return 1;
				}
				else 
				{
					return 0;
				}
			}
		}		
	}
	for(int i=r;i>=l;i--)
	{
		if(c[i]==')')
		{
			i=p[i];
		}
		if(c[i]=='&')
		{
			bool x=dfs(l,i-1);
			if(!x)
			{
		//		cout<<l<<' '<<i-1<<'&'<<i+1<<' '<<r<<endl;
				b++;
				return 0;
			}
			else{
				bool y=dfs(i+1,r);
				if(!y)
				{
					return 0;
				}
				else 
				{
					return 1;
				}
			}
		}		
	}
}
int main()
{
	scanf("%s",c+1);
	n=strlen(c+1);
	for(int i=1;i<=n;i++)
	{
		if(c[i]=='(')s.push(i);
		if(c[i]==')')
		{
			p[s.top()]=i;
			p[i]=s.top();
	//		cout<<s.top()<<' '<<i<<endl;
			s.pop();
		}
	}
	printf("%d\n",dfs(1,n));
	printf("%lld %lld",b,a);
	return 0;
}
/*
DengDuck want to AK CSP
So I asked you to wish DengDuck AK CSP
So DengDuck AK CSP
But Wangziye 401 
Orz Wangziye 
*/ 
2022/10/30 19:01
加载中...