QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#544117#7894. Many Many HeadsNew_FolderWA 0ms3660kbC++20843b2024-09-02 09:45:522024-09-02 09:45:52

Judging History

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

  • [2024-09-02 09:45:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3660kb
  • [2024-09-02 09:45:52]
  • 提交

answer

#pragma GCC optimize("O2")
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
// ( and ) is 1, [ and ] is 0.
string s;
int n;
int flag=0;
int dfs(int x){
	int cnt1=0;
	for(int i=x+1;i<n;i++){
		if((s[i]=='['||s[i]==']')&&cnt1%2==0){
			if(cnt1>=4){
				flag=1;
			}
			return i;
		}else if((s[i]=='['||s[i]==']')&&cnt1%2==1){
			i=dfs(i);
		}else{
			cnt1++;
		}
	}
	return 0;
}
void solve(){
	cin>>s;
	n=s.length();
	int cnt1=0;
	for(int i=0;i<n;i++){
		if(s[i]==']'||s[i]=='['){
			i=dfs(i);
		}else{
			cnt1++;
		}
	}
	if(flag||cnt1>=4){
		cout<<"No\n";
	}else{
		cout<<"Yes\n";
	}
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
        flag=0;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

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

output:

Yes
Yes

result:

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