QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#387541#3734. Parenthesisucup-team1251WA 1ms3644kbC++171.5kb2024-04-12 16:33:002024-04-12 16:33:01

Judging History

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

  • [2024-04-12 16:33:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3644kb
  • [2024-04-12 16:33:00]
  • 提交

answer

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<math.h>
#include<set>
#include<bitset>
#include<deque>
#include<unordered_map>
#include<algorithm>
#define int long long
using namespace std;
typedef pair<int,int>PII;
const int N=1e5+10,M=5e2+10;
int sum[N],sum1[N],sum2[N];

signed main(){
	ios::sync_with_stdio(false);
	cin.tie();
	cout.tie();
	int n,m;
	while(cin>>n>>m){
		string s;
		cin>>s;
		s=" "+s;
		int ll=s.length();
		int f=1,g=1;
		for(int i=1;i<ll;i++){
			if(s[i]=='(') sum[i]=sum[i-1]+1;
			else sum[i]=sum[i-1]-1;
			if(sum[i]<0) g=0;
			if(sum[i]<=-3) f=0;
			if(sum[i]<=1){
				sum1[i]=sum1[i-1]+1;
				if(sum[i]==-1 || sum[i]==-2) sum2[i]=sum2[i-1]+1;
				else{
					sum2[i]=sum2[i-1];
				}
			}
			else{
				sum1[i]=sum1[i-1];
				sum2[i]=sum2[i-1];				
			}
		}
//		for(int i=1;i<ll;i++) cout<<sum[i]<<" "<<sum1[i]<<" "<<sum2[i]<<endl;
		if(sum[ll-1]!=0) f=0;
		if(f){
			for(int i=1;i<=m;i++){
				int l,r;
				cin>>l>>r;
				if(s[l]==s[r]){
					if(g==0) cout<<"No\n";
					else cout<<"Yes\n";
				}
				else{
					int flag=1;
					if(sum2[l-1]!=0 || sum2[ll-1]-sum2[r-1]!=0) flag=0;
					if(s[l]=='('){
						if(sum1[r-1]-sum1[l-1]!=0) flag=0;
					}
					if(flag==1) cout<<"Yes\n";
					else cout<<"No\n";
				}
			}
		}
		else{
			for(int i=1;i<=m;i++){
				int l,r;
				cin>>l>>r;
				cout<<"No\n";
			}
		}
	}
	return 0;
}
//18 3
//((())))()()(()(())
//7 11
//7 12
//7 8
//18 1
//((()))))()((()(())
//7 11

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3644kb

input:

10 100
(()())()()
1 2
4 2
3 1
2 3
4 1
3 2
5 4
2 4
1 5
4 3
3 5
3 1
5 3
2 5
4 5
3 5
4 2
5 4
3 5
2 3
4 1
2 4
2 5
2 5
3 4
4 1
5 1
1 2
5 1
2 3
4 2
1 3
2 3
2 1
4 1
1 5
5 1
3 4
3 4
1 5
1 4
1 3
4 1
3 5
1 2
3 1
1 2
2 3
5 3
2 1
3 5
1 5
5 4
2 1
1 4
4 5
4 1
4 1
2 4
5 3
5 4
3 2
3 5
5 4
3 5
1 4
5 1
1 5
3 2
3 4
2 ...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
No
Yes
Yes
Yes
No
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Y...

result:

wrong answer 3rd words differ - expected: 'No', found: 'Yes'