QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#304615#7894. Many Many HeadsjiajieshiWA 1ms9800kbC++174.0kb2024-01-13 21:52:482024-01-13 21:52:48

Judging History

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

  • [2024-01-13 21:52:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9800kb
  • [2024-01-13 21:52:48]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long 
#define pii pair<int,int>
#define pss pair<string,string>
#define fi first
#define se second
#define pb push_back
#define un unsigned
#define ull unsigned long long
#define	int_INF 0x3f3f3f3f
#define LL long long
#define ll_INF 0x3f3f3f3f3f3f3f3f
#define lb long double
#define db double
#define re return
#define pll pair<ll,ll>
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define debug(a) cout<<"debug: "<<(#a)<<" = "<<a<<'\n'
#define cer(a) cerr<<#a<<'='<<(a)<<"@ line"<<__LINE__<<endl
#define cer2(a,b) cerr<<#a<<'='<<(a)<<','<<#b<<'='<<(b)<<"@ line"<<__LINE__<<endl
#define cer3(a,b,c) cerr<<#a<<'='<<(a)<<','<<#b<<'='<<(b)<<','<<#c<<'='<<(c)<<','<<"@ line"<<__LINE__<<endl
#define pdd pair<db,db>
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define KV(x) #x << " = " << x << ";"
#define DEBUG DebugLine(__LINE__)
using namespace std;
const int maxn=2e5+100;
const ll mode=998244353;
const int mode2=1e6+5;
const ll inf=9223372036854775807;
const db eps=1e-6;
typedef pair<int,int> hashv;
mt19937 mrand(random_device{}()); 
hashv operator + (hashv a,hashv b) {
	int c1=a.fi+b.fi,c2=a.se+b.se;
	if (c1>=mode) c1-=mode;
	if (c2>=mode2) c2-=mode2;
	return mp(c1,c2);
}

hashv operator - (hashv a,hashv b) {
	int c1=a.fi-b.fi,c2=a.se-b.se;
	if (c1<0) c1+=mode;
	if (c2<0) c2+=mode2;
	return mp(c1,c2);
}

hashv operator * (hashv a,hashv b) {
	return mp(1ll*a.fi*b.fi%mode,1ll*a.se*b.se%mode2);
}
int rnd(int x) { return mrand() % x;}
struct DebugLine {
  explicit DebugLine(int lineno) { std::cerr << lineno << "L "; }
 
  ~DebugLine() { std::cerr << std::endl; }
 
  template <typename T> DebugLine &operator<<(T &&v) {
    std::cerr << std::forward<T>(v);
    return *this;
  }
};
double PI = 3.141592653;
double my_cos(double x){
    return cos(x*PI / 180.0);
}
double my_sin(double x){
    return sin(x*PI / 180.0);
}
double my_tan(double x){
    return tan(x*PI / 180.0);
}
ll n,m,a[maxn];
ll sum,ans;
string str;
vector<int>vt;
int vis[maxn]; 
ll ksm(ll a,ll b)
{
	ll res=1ll;
	while(b)
	{
		if(b&1)
		res=res*a%mode;
		b>>=1;
		a=a*a%mode;
	}
	return res;
}
struct Hash_char{
    const ll mod=998244353, base=131;
    ll p[maxn], g[maxn];
    void getp(){
        p[0]=1;
        for(int i=1; i<maxn; i++){
            p[i]=p[i-1]*base%mod;
        }
    }
    LL Hash(char s[]){
        int len=strlen(s+1);
        g[0]=0, g[1]=s[1];
        for(int i=2; i<=len; i++){
            g[i]=(g[i-1]*base+s[i])%mod;
        }
        return g[len];
    }
    LL getLR(int l, int r){//µÃµ½s[l]-s[r]µÄhashÖµ 
        if(l>r) return 0;
        LL ans=((g[r]-g[l-1]*p[r-l+1])%mod+mod)%mod;
        return ans;
    }
    
 
}T[2];
LL strfz(int pos, int l, int r){//pos:Õý·´´®,·­×ªl, r¡£ 
    LL ans=T[pos].getLR(1, l-1)*T[pos].p[n-l+1]%T[pos].mod;
    LL res=T[pos^1].getLR(n-r+1, n-r+1+r-l)*T[pos].p[n-r]%T[pos].mod;
    ans=ans+res+T[pos].getLR(r+1, n);
    return ans%T[pos].mod;
}
ll pre[maxn][2];
void solve()
{
	ll sum_Y=0,sum_F=0;
    cin>>str;
    n=str.length();
    for(int i=0;i<n;i++)
    {
    	if(str[i]=='('||str[i]==')')
    	sum_Y++;
    	else sum_F++;
	}
	pre[0][0]=pre[0][1]=0;
	
	if(str[0]=='('||str[0]==')')
	pre[0][0]++;
	else pre[0][1]++;
	
	for(int i=1;i<n;i++)
	{
		pre[i][0]=pre[i-1][0];
		pre[i][1]=pre[i-1][1];
		
		if(str[i]=='('||str[i]==')')
	    pre[i][0]++;
	    else pre[i][1]++;
	    
	}
	
	for(int i=2;i<n-1;i++)
	{
		if(pre[i-1][0]%2==0&&pre[i-1][1]%2==0)
		{
			cout<<"NO"<<'\n';
			return;
		}
	}
	cout<<"YES"<<'\n';
	
	
}
int main(){
	#ifndef ONLINE_JUDGE
		freopen("C:\\Users\\JIAJIEASHI\\Desktop\\in.cpp","r",stdin);
	//	freopen("out.cpp","w",stdout);
	#endif
    ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int test_case;
	test_case=1;
	cin>>test_case;
	while(test_case--) 
    solve();
	return 0;
}



详细

Test #1:

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

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

input:

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

output:

NO
NO

result:

wrong answer expected YES, found NO [1st token]