UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#210702#3785. 恒真huangyuhang1003ms1256kbC++111.6kb2024-08-07 10:10:182024-08-07 12:07:34

answer

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
struct node
{
	node *lchild=nullptr,*rchild=nullptr;
	char chr;
	bool b=false;
}; 
set<char>S;
vector<char>V;
map<char,int>mp;
int get(int a,int b,char c)
{
	if(c=='|')
		return a|b;
	else if(c=='&')
		return a&b;
	else 
		return a^b;
}
int check(node* ans)
{
	if(ans->chr=='|'||ans->chr=='&'||ans->chr=='^')
		if(!ans->b)
			return get(check(ans->lchild),check(ans->rchild),ans->chr);
		else
			return !get(check(ans->lchild),check(ans->rchild),ans->chr);
	else
	{
		if(!ans->b)
			return mp[ans->chr];
		else
			return !mp[ans->chr];
	}
			
}
int end_depth;
set<int>lk;
node* root;
void DFS(int depth)
{
	if(depth==end_depth)
	{
		lk.insert(check(root));
		return;
	}
	else
	{
		mp[V[depth]]=0;
		DFS(depth+1);
		mp[V[depth]]=1;
		DFS(depth+1);
	} 
}
int main()
{
	string str;
	getline(cin,str);
	stack<node*>st;
	int length=str.size();
	for(int i=0;i<length;i++)
	{
		if(str[i]==' ')
			continue;
		else if(str[i]=='|'||str[i]=='&'||str[i]=='^')
		{
			node* lc=st.top();
			st.pop();
			node* rc=st.top();
			st.pop();
			node* top=new node;
			top->chr=str[i];
			top->lchild=lc;
			top->rchild=rc;
			st.push(top);
		}
		else if(str[i]=='!')
		{
			node* top=st.top();
			st.pop();
			top->b=!top->b;
			st.push(top);
		}
		else
		{
			S.insert(str[i]);
			node* top=new node;
			top->chr=str[i];
			st.push(top);
		}
	}
	for(auto p:S)
		V.push_back(p);
	end_depth=V.size();
	root=st.top();
	st.pop();
	DFS(0);
	if(lk.count(0))
		cout<<"NO";
	else
		cout<<"YES";
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 30
Accepted

Test #1:

score: 30
Accepted
time: 0ms
memory: 1236kb

input:

a a | a b & |

output:

NO

result:

ok "NO"

Test #2:

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

input:

a b | a b | & a b | a b | & &

output:

NO

result:

ok "NO"

Test #3:

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

input:

a b | c d | & e f | g h | & &

output:

NO

result:

ok "NO"

Test #4:

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

input:

c d |

output:

NO

result:

ok "NO"

Test #5:

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

input:

a a & b & b a & b b & & | b b | b b | & b b a & | | | b b & a a & & b a | a a | & & b a a | | a a & ...

output:

NO

result:

ok "NO"

Test #6:

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

input:

b a b | | b d & c b & & & d d | a | d c & b b & | & & c c & d & d a & d a & & | b & & a c & b b | | ...

output:

NO

result:

ok "NO"

Test #7:

score: 0
Accepted
time: 1ms
memory: 1248kb

input:

g d | f a & | h a & a a & | & d a e & e g & & | & b e & a a | & g f & h a & & & h e | f g | | e c & ...

output:

NO

result:

ok "NO"

Test #8:

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

input:

c b & a a | | g g h | & | a e | g b & | f f | c c & & & | b c b | f b | | | b e | f | b d & c a & | ...

output:

NO

result:

ok "NO"

Subtask #2:

score: 30
Accepted

Test #9:

score: 30
Accepted
time: 0ms
memory: 1228kb

input:

a a & a ! & a a | a a | & & ! a a a | & a a | a | | a a | a a & | ! | | a ! ! ! ! a a | a ! & ! ! | ...

output:

YES

result:

ok "YES"

Test #10:

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

input:

a ! ! a a | a a & & | a a ! | a a & ! & & ! ! a ! ! a & a ! ! a a & a ! | | & a a & a a & | a a | ! ...

output:

NO

result:

ok "NO"

Test #11:

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

input:

a ! ! a a | a a & & | a a ! | a a & ! & & ! ! a ! ! a & a ! ! a a & a ! | | & a a & a a & | a a | ! ...

output:

NO

result:

ok "NO"

Test #12:

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

input:

a a a | ! | a & a a a | ! & a | | a a & ! a a & a a | | & ! a a a & | a a | a | & a a | a a | | a ! ...

output:

YES

result:

ok "YES"

Test #13:

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

input:

a a ! a a | ^ a a | a a | ^ | a a | a ^ a ! a ! | ^ | ! | a a a | ! & a ! a | a a ^ a a ^ & | ^ a ^ ...

output:

NO

result:

ok "NO"

Test #14:

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

input:

a a a a | a a | | a a | a a | ^ & ! a a | ! a a | a & | a | & & a a & a a ^ & a a | a ! | ^ a a & ! ...

output:

NO

result:

ok "NO"

Test #15:

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

input:

a a ! a a ^ ^ a ! | | a a | a a | ^ a a | ! | a a | a a | | a a | a | ^ | | a | a a | a a | | a ! a ...

output:

YES

result:

ok "YES"

Subtask #3:

score: 40
Accepted

Test #16:

score: 40
Accepted
time: 0ms
memory: 1236kb

input:

a b | a ! b ! | |

output:

YES

result:

ok "YES"

Test #17:

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

input:

a b ! | a ! b | &

output:

NO

result:

ok "NO"

Test #18:

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

input:

a b ! | a ! b | |

output:

YES

result:

ok "YES"

Test #19:

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

input:

a b | c ! | a ! b | c | | a b ! c | | |

output:

YES

result:

ok "YES"

Test #20:

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

input:

c b b | | b b | c c | | | c ! c b | ^ ! ^ b c | b c | | c c | ! ^ b ! | | a a | b a | | b b | ! | ! ...

output:

NO

result:

ok "NO"

Test #21:

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

input:

b a | a a | ^ b | b a a & | ! | b ! c a ^ | ! a ^ | c ! ! b b | ! ^ c b | a | b & | b a | ! c c | a ...

output:

NO

result:

ok "NO"

Test #22:

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

input:

b ! b | c a c | ! | ! a c | b c | | ! b c a | c a | | | | ^ b c | c ! & a c & c c | | | c a | ! a ! ...

output:

YES

result:

ok "YES"

Test #23:

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

input:

d c c | ! c ! c ! | | | ! c a | d ! | c b | a d | | | d c ^ ! c c | ! | | b b | b | b a | ! | b b b ...

output:

NO

result:

ok "NO"

Test #24:

score: 0
Accepted
time: 1ms
memory: 1240kb

input:

b ! c ! d d | | d c ^ d d | | | ! d a | ! ! ! | c a c | d ! | ^ ! c a | c d | | a c | d c | ^ | b c ...

output:

NO

result:

ok "NO"

Test #25:

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

input:

b ! g ! h d | | d g ^ h d | | | ! d e | ! ! ! | g e c | h ! | ^ ! g e | c d | | e c | h c | ^ | b g ...

output:

NO

result:

ok "NO"

Test #26:

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

input:

b ! g ! h d | | d g ^ h d | | | ! d e | ! ! ! | g ! ! d ! ! h c | d ^ ! | | | c ! g e | | ! ! b b g ...

output:

NO

result:

ok "NO"

Test #27:

score: 0
Accepted
time: 1ms
memory: 1236kb

input:

a ! b | c | d | a b ! | c | d | | a b | c ! | d | | a b | c | d ! | |

output:

YES

result:

ok "YES"

Test #28:

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

input:

a a ! | b b ! | & c c ! | d d ! | & & e e ! | f f ! | & & g ! g | h ! h | & &

output:

YES

result:

ok "YES"

Extra Test:

score: 0
Extra Test Passed