QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#301233#7894. Many Many Headsship2077WA 0ms3764kbC++14752b2024-01-09 16:20:132024-01-09 16:20:13

Judging History

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

  • [2024-01-09 16:20:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3764kb
  • [2024-01-09 16:20:13]
  • 提交

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,bool>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]=a[i];
		if (mp[a[i+1]][Hash]) return puts("No"),void();
		mp[a[i+1]][Hash]=1;
	}
	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: 0ms
memory: 3764kb

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: -100
Wrong Answer
time: 0ms
memory: 3692kb

input:

2
(([([[([
]]))])]])]

output:

Yes
Yes

result:

wrong answer expected NO, found YES [2nd token]