QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#613178#7894. Many Many Headswsxcb#WA 3ms3832kbC++171.0kb2024-10-05 13:41:582024-10-05 13:41:59

Judging History

你现在查看的是最新测评结果

  • [2024-10-05 13:41:59]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3832kb
  • [2024-10-05 13:41:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define fi first
#define se second
const int N = 1e5 + 5;

void solve() {
	string s;
	cin >> s;
	int n = s.size();
	s = "#" + s;
	for (int i = 1; i <= n; i++) {
		if (s[i] == '(' || s[i] == ')')
			s[i] = '1';
		else
			s[i] = '0';
	}
	//cout << s << '\n';
	stack<char>st;
	int cnt = 0;
	char last = '#';
	for (int i = 1; i <= n; i++) {
		if ((int)st.size() == 0) {
			cnt++;
			if (s[i] == s[i - 1]) {
				cout << "No\n";
				return ;
			}
			if (cnt == 3) {
				cout << "No\n";
				return ;
			}
			st.push(s[i]);
		} else if (s[i] == st.top()) {
			if (s[i] == last) {
				cout << "No\n";
				return ;
			}
			last = s[i];
			st.pop();
		} else {
			st.push(s[i]);
		}
		//cout << st.size() << ' ';
	}
	if (st.size() == 0)
		cout << "Yes\n";
	else
		cout << "No\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	cin >> t;
	while (t--)
		solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3532kb

input:

6
))
((()
[()]
()[()]()
([()])
([])([])

output:

Yes
No
Yes
No
Yes
No

result:

ok 6 token(s): yes count is 3, no count is 3

Test #2:

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

input:

2
(([([[([
]]))])]])]

output:

Yes
No

result:

ok 2 token(s): yes count is 1, no count is 1

Test #3:

score: -100
Wrong Answer
time: 3ms
memory: 3600kb

input:

15134
][
)(
)([[
[)([
)][)
]])(
([]([]
]]))][
[([](]
()[))]
][(]](
([()[)
()[]((
[)([)(
]]([[)]]
)[()])]]
))[](([]
](([((]]
))[)][)[
[)])([(]
[()[]))[
)][(]()]
[[((]()]
((]])[[)
])(](]])
)]]()[](
([)[])])
[[)[()](
([[)[[()
[[)([]))
[)[[)[()
))[(([)(
()][)[](]]
[()]([[([[
)[]))][)][
)]([]([(][
[])])(...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
No
No
Yes
No
Yes
No
Yes
No
No
Yes
Yes
No
No
No
No
No
No
Yes
Yes
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
No
Yes
No
Yes
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
Yes
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
N...

result:

wrong answer expected YES, found NO [10th token]