QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#301245#7894. Many Many Headsship2077WA 7ms3904kbC++14758b2024-01-09 16:34:252024-01-09 16:34:26

Judging History

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

  • [2024-01-09 16:34:26]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3904kb
  • [2024-01-09 16:34:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
mt19937_64 mt(time(NULL));
constexpr int M=1e5+5;string s;
int n,tp,a[M],stk[M];
ull Hash,val[2],base[M];
void solve(){
	cin>>s;n=s.length();s=" "+s;
	val[0]=mt();val[1]=mt();Hash=0;
	for (int i=1;i<=n;i++) base[i]=mt();
	for (int i=1;i<=n;i++) a[i]=s[i]=='('||s[i]==')';
	unordered_map<ull,int>mp[2];mp[a[1]][0]=1;
	for (int i=1;i<=n;i++){
		if (tp&&a[stk[tp]]==a[i])
			Hash-=base[tp--]*val[a[i]];
		else Hash+=base[++tp]*val[a[i]],stk[tp]=i;
		if (mp[a[i]][Hash]>1) return puts("No"),void();
		if (i<n) mp[a[i+1]][Hash]++;
	}
	puts("Yes");
}
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T;cin>>T;while (T--) solve();
	return 0;
}

詳細信息

Test #1:

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

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

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

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

result:

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