QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#717169#7894. Many Many HeadslihuaWA 3ms3864kbC++202.0kb2024-11-06 17:06:342024-11-06 17:06:39

Judging History

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

  • [2024-11-06 17:06:39]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3864kb
  • [2024-11-06 17:06:34]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define int long long
const int N = 2e6 + 10;
const int INF = 0x3f3f3f3f3f3f3f3fLL;
typedef __int128 ll;

int a[N];
string s;

void solve() {
	int k = 0;
	cin >> s;
	for (register int i = 0; i < s.size(); ++i) {
		if (s[i] == '(' || s[i] == ')')	a[++k] = 1;
		else	a[++k] = 0;
	}
	stack<int> st;
	int cnt = 0, tmp = 0;
	for (register int i = 1; i <= k; ++i) {
		if (st.empty()) {
			st.push(a[i]);
		}
		else {
			if (st.top() == 0) {
				if (a[i] == 1)	cnt += st.size() - 1, ++tmp;
				else {
					cnt = !(tmp & 1) ? 0 : cnt;
					st.pop(), tmp = 0;
				}
			}
			else {
				if (st.size() >= 3 + cnt) {
					cout << "No" << "\n";
					return;
				}
				st.push(a[i]);
				if (st.size() >= 3 + cnt && st.top()) {
					cout << "No" << "\n";
					return;
				}
			}
		}
	}
	if (!st.empty() && st.top() && st.size() >= 3 + cnt) {
		cout << "No" << "\n";
		return;
	}
	while (!st.empty()) {
		st.pop();
	}
	cnt = 0;
	for (register int i = 1; i <= k; ++i) {
		if (st.empty()) {
			st.push(a[i]);
		}
		else {
			if (st.top() == 1) {
				if (a[i] == 0)	cnt += st.size() - 1, ++tmp;
				else {
					cnt = !(tmp & 1) ? 0 : cnt;
					st.pop(), tmp = 0;
				}
			}
			else {
				if (st.size() >= 3 + cnt) {
					cout << "No" << "\n";
					return;
				}
				st.push(a[i]);
				if (st.size() >= 3 + cnt && !st.top()) {
					cout << "No" << "\n";
					return;
				}
			}
		}
	}
	if (!st.empty() && !st.top() && st.size() >= 3 + cnt) {
		cout << "No" << "\n";
		return;
	}
	cout << "Yes" << "\n";
	return;
}

signed 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: 3656kb

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

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

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

result:

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