求助WAon #11, #15, HACK #2
  • 板块P1575 正误问题
  • 楼主zlttcl
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/7/8 16:33
  • 上次更新2023/10/23 10:51:28
查看原帖
求助WAon #11, #15, HACK #2
555381
zlttcl楼主2023/7/8 16:33

RT,

//#pragma G++ optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans, tot, Not, cnt, a[114514], Ans[114514];
string s, last = "or";
bool fan, p[114514];
inline ll read(){
	ll x = 0, m = 1;
	char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') m = -1;
		ch = getchar();
	}
	while(isdigit(ch)){
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return x * m;
}
inline void write(ll x){
	if(x < 0){
		putchar('-');
		write(-x);
		return;
	}
	if(x >= 10) write(x / 10);
	putchar(x % 10 + '0');
}
signed main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
    while(cin >> s){
    	if((s == "or" || s == "and") && (last == "not" || last == "or" || last == "and")){
    	    cout << "error";
			return 0;	
		}
		if((s == "true" || s == "false") && (last == "true" || last == "false")){
			cout << "error";
			return 0;
		}
    	if(s == "not"){
    		++ Not;
    		fan = true;
		}else if(s == "true"){
			if(fan && Not % 2){
				a[++ tot] = 48;
			}else{
				a[++ tot] = 49;
			}
			Not = 0;
			fan = false;
		}else if(s == "false"){	
			if(fan && Not % 2){
				a[++ tot] = 49; 
			}else{
				a[++ tot] = 48;
			}
			Not = 0;
			fan = false;
		}else if(s == "or"){
			Not = 0;
			a[++ tot] = '^';
		}else if(s == "and"){
			Not = 0;
			a[++ tot] = '&';
		}
		last = s;
	}
	if(s == "not" || s == "and" || s == "or"){
		cout << "error";
		return 0;
	}
	p[0] = true;
	for(int i = 1; i <= tot; ++ i){
		if(!p[i - 1] && a[i] != '&' && (a[i - 1] == 48 || a[i - 1] == 49)){
			Ans[++ cnt] = (a[i - 1] - 48);
			continue;
		}
		if(a[i] != '&') continue;
		p[i] = p[i - 1] = p[i + 1] = true;
		Ans[++ cnt] = ((a[i - 1] - 48) && (a[i + 1] - 48));
	}
	for(int i = 1; i <= cnt; ++ i){
		ans = (ans || Ans[i]);
	}
	cout << (ans ? "true" : "false");
	return 0;
}

2023/7/8 16:33
加载中...