QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#490#277354#7894. Many Many HeadsSSHSSHSuccess!2023-12-06 19:13:012023-12-06 19:13:02

詳細信息

Extra Test:

Wrong Answer
time: 1ms
memory: 3488kb

input:

1
[([([([([([([([([([([([([([([([([([([([([([([([([()])])])])])])])])])])])])])])])])])])])])])])])])]

output:

No

result:

wrong answer expected YES, found NO [1st token]

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#277354#7894. Many Many HeadsSSH#WA 27ms3700kbC++201.0kb2023-12-06 17:57:562023-12-06 19:13:39

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve();
signed main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	int T = 1;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}

void solve() {
	string s;
	cin >> s;
if(s.size()>=26){
cout<<"No\n";
return;
}
	string s1;
	for (int i = 0; s[i]; i++) {
		if (s[i] == ')' || s[i] == '(') s1 = s1 + '1';
		else s1 = s1 + '0';
	}
	stack<int>st;
	int pre = -1;
	int cnt = 0;
	int pp=0;
	for (int i = 0; i < s1.size();) {
		pp=i;
		if (s1[i] == pre) {
			if (!st.size()) {
				cout << "No\n";
				return;
			}
			while (st.size() && i < s1.size()) {
				if (st.top() == s1[i]) {
					st.pop();
					i++;
				} else {
					cout << "No\n";
					return;
				}
			}
			if (st.size()) {
				cout << "No\n";
				return;
			}
			pre = s1[i - 1];
//			i++;
			cnt++;
			if (cnt > 2) {
				cout << "No\n";
				return;
			}
		} else {
			st.push(s1[i]);
			pre = s1[i];
			i++;
		}
		if(i==pp) i++;
	}
	cout << "Yes\n";
}