QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#688101#7894. Many Many HeadsVarealWA 1ms6008kbC++172.0kb2024-10-29 23:21:542024-10-29 23:21:55

Judging History

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

  • [2024-10-29 23:21:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6008kb
  • [2024-10-29 23:21:54]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <bitset>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <cassert>
#include <random>
#include <chrono>
#include <ctime>
#include <cstdlib>
#define pii pair<int,int> 
#define mp make_pair
#define pb emplace_back
#define debug() cout<<"qwq"<<endl
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned long long ull;
const int DMAX = 1000000 + 5;
const double INF = 1e9;
const int MOD = 998244353;
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
template<class T> inline void read(T &x){
	T f=1; x=0; char ch=getchar();
	while(ch<'0' || ch>'9'){
		if(ch=='-') f=-1; 
		ch=getchar();
	}
	while(ch<='9' && ch>='0'){ x=x*10+ch-'0';ch=getchar(); }
	x*=f;
}
int T, n;
char s[DMAX];
int a[DMAX];
vector<int> v0, v1;
void solve(){
	scanf("%s", s + 1);
	v0.clear(), v1.clear();
	n = strlen(s + 1);
	for(int i = 1; i <= n; i++){
		if(s[i] == '(' || s[i] == ')'){
			a[i] = 1;
			v0.pb(i);
		}
		else a[i] = 0, v1.pb(i);
	}
	for(int i = 1; i <= n - 2; i++){
		if(a[i] == a[i + 1] && a[i + 1] == a[i + 2]){
			puts("No");
			return ;
		}
	}
	int cnt0 = 0, cnt1 = 0;
	int las = -1;
	int len = v0.size();
	for(int i = 0; i < len; i += 2){
		if(v0[i] + 1 == v0[i + 1]) cnt0 ++;
	}
	len = v1.size();
	for(int i = 0; i < len; i += 2){
		if(v1[i] + 1 == v1[i + 1]) cnt1 ++;
	}
	// cout<<cnt1<<" "<<cnt0<<endl;
	if(cnt1 <= 1 && cnt0 <= 1){
		puts("Yes");
		return ;
	}
	string str = "";
	for(int i = 1; i <= n; i++){
		if(s[i] == '(' || s[i] == ')'){
			str += "1";
		}
		else str += "0";
	}
	if(str == "011011" || str == "100100" || str == "110110" || str == "001001"){
		puts("Yes");
		return ;
	}
	else puts("No");
	return ;
}
int main(){
    read(T);
	while(T--){
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

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

output:

Yes
Yes

result:

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