QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#668322#7894. Many Many HeadsnageingWA 8ms3620kbC++201019b2024-10-23 13:37:102024-10-23 13:37:16

Judging History

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

  • [2024-10-23 13:37:16]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:3620kb
  • [2024-10-23 13:37:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
bool chmin(int &x, int y) {
	if (x > y) {
		x = y;
		return 1;
	}
	return 0;
}
bool chmax(int &x, int y) {
	if (x < y) {
		x = y;
		return 1;
	}
	return 0;
}

void solve() {
	string s;
	cin >> s;
	int n = s.size();
	vector<int> cnt(2);
	stack<int> stk;
	map<char, int> mp;
	mp['('] = 0; mp[')'] = 0;
	mp['['] = 1; mp[']'] = 1;
	bool ok = 1;
	for (int i = 0; i < n; i ++) {
		if (stk.empty()) {
			stk.push(mp[s[i]]);
		} else {
			if (stk.top() == mp[s[i]]) {
				stk.pop();
				if (stk.empty()) {
					cnt[mp[s[i]]] ++;
				} else {
					if (stk.top() == mp[s[i]]) {
						ok = 0;
					}
				}
			} else {
				stk.push(mp[s[i]]);
			}
		}
	}
	ok &= (cnt[0] < 2 && cnt[1] < 2);

	cout << (ok ? "Yes\n" : "No\n");
}

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

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 8ms
memory: 3612kb

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]