QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#299878#7894. Many Many HeadskiwiHM#WA 2ms7788kbC++14853b2024-01-07 12:47:572024-01-07 12:47:59

Judging History

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

  • [2024-01-07 12:47:59]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7788kb
  • [2024-01-07 12:47:57]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e6 + 5;

int n;
int stk[maxn], match[maxn];
char s[maxn];

inline bool solve(int l, int r){
	if(l > r) return true;
	int cnt[2] = {0, 0};
	for(int it = l; it < r; it = match[it] + 1){
		if(!solve(it + 1, match[it] - 1)) return false;
		++cnt[s[it] == '('];
	}
	if(cnt[0] >= 2 || cnt[1] >= 2) return false;
	return true;
}

inline void solve(){
	scanf("%s", s); n = strlen(s);
	int top = 0;
	for(int i = 0; i < n; ++i){
		if(top && (stk[top] & 1) == (s[i] == '[' || s[i] == ']')){
			match[i] = (stk[top] >> 1);
			match[stk[top] >> 1] = i;
			--top;
		}
		else
			stk[++top] = i << 1 | (s[i] == '[' || s[i] == ']');
	}
	int ans = solve(0, n - 1);
	puts(ans ? "Yes" : "No");
}

int main(){
	int T;
	for(scanf("%d", &T); T--; solve());
	return 0;
}

详细

Test #1:

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

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: 1ms
memory: 5672kb

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: 2ms
memory: 7788kb

input:

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

output:

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

result:

wrong answer expected YES, found NO [3rd token]