神奇20pts过大样例求Hack
查看原帖
神奇20pts过大样例求Hack
287947
Icyfires18楼主2023/1/12 20:19

这是20pts的提交记录

四个样例全过,但是60个点只过了9个点,是不是说明题目的大样例有很大的局限性(不懂),求一份Hack。

思路是普通的表达式求值加上短路判定(短路标记内的不判定)。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e6+7;
int len,cnt0,cnt1;
int vtop,ctop,fg;
char s[N],c[N];
bool v[N];
inline int lv(char ch){
	if(ch=='|')return 1;
	if(ch=='&')return 2;
	return 0;
}
inline bool calc(bool a,char ch,bool b){
	if(ch=='|')return a|b;
	if(ch=='&')return a&b;
	return 0;
}
void pop(char ch){
	while(lv(c[ctop])>=lv(ch))
		v[--vtop]=calc(v[vtop],c[ctop--],v[vtop+1]);
	if(ctop<fg)fg=0;
}
int main(){
	register int i,k;
	scanf("%s",s+1);
	len=strlen(s+1);
	for(i=1;i<=len;++i){
		if(s[i]=='0')v[++vtop]=0;
		if(s[i]=='1')v[++vtop]=1;
		if(s[i]=='|'){
			pop('|');
			c[++ctop]='|';
			if(v[vtop]&&!fg)
				fg=ctop,++cnt1;
		}
		if(s[i]=='&'){
			pop('&');
			c[++ctop]='&';
			if(!v[vtop]&&!fg)
				fg=ctop,++cnt0;
		}
		if(s[i]=='(')c[++ctop]='!';
		if(s[i]==')')pop('|'),--ctop;
	}pop('|');
	printf("%d\n",v[1]);
	printf("%d %d\n",cnt0,cnt1);
	return 0;
}
2023/1/12 20:19
加载中...