QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#612999#7894. Many Many Headswsxcb#WA 1ms3820kbC++17959b2024-10-05 13:24:392024-10-05 13:24:45

Judging History

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

  • [2024-10-05 13:24:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3820kb
  • [2024-10-05 13:24:39]
  • 提交

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;
int a[N];
char ch[N];

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;
	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()) {
			st.pop();
		} else {
			st.push(s[i]);
		}
	}
	if (st.size() == 0)
		cout << "Yes\n";
	else
		cout << "No\n";
}

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

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3596kb

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: 3756kb

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: 0ms
memory: 3820kb

input:

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

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
No
Yes
No
Yes
No
No
Yes
Yes
No
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
No
Yes
No
Yes
Yes
Yes
No
No
No
Yes
No
No
No
No
Yes
No
No
No
Yes
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...

result:

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