QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#301245 | #7894. Many Many Heads | ship2077 | WA | 7ms | 3904kb | C++14 | 758b | 2024-01-09 16:34:25 | 2024-01-09 16:34:26 |
Judging History
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]