Submission #100996

# Submission time Handle Problem Language Result Execution time Memory
100996 2019-03-16T02:05:24 Z TAISA_ Security Gate (JOI18_security_gate) C++14
12 / 100
42 ms 428 KB
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll MOD=1000000007LL;
const ll INF=(1<<30);
const ll LINF=(1LL<<60);
template<typename T> void chmax(T &a,T b){a=max(a,b);}
template<typename T> void chmin(T &a,T b){a=min(a,b);} 
struct Max{
	int n;
	vector<int> dat;
	Max(int n_){
		n=1;
		while(n<n_)n<<=1;
		dat.resize(2*n,-INF);
	}
	void update(int k,int x){
		k+=n;
		dat[k]=x;
		k>>=1;
		while(k>0){
			dat[k]=max(dat[k<<1],dat[k<<1|1]);
			k>>=1;
		}
	}
	int query(int l,int r){
		l+=n;r+=n;
		int res=-INF;
		for(++r;l<r;l>>=1,r>>=1){
			if(l&1)chmax(res,dat[l++]);
			if(r&1)chmax(res,dat[--r]);
		}
		return res;
	}
};
struct Min{
	int n;
	vector<int> dat;
	Min(int n_){
		n=1;
		while(n<n_)n<<=1;
		dat.resize(2*n,INF);
	}
	void update(int k,int x){
		k+=n;
		dat[k]=x;
		k>>=1;
		while(k>0){
			dat[k]=min(dat[k<<1],dat[k<<1|1]);
			k>>=1;
		}
	}
	int query(int l,int r){
		l+=n;r+=n;
		int res=INF;
		for(++r;l<r;l>>=1,r>>=1){
			if(l&1)chmin(res,dat[l++]);
			if(r&1)chmin(res,dat[--r]);
		}
		return res;
	}
};
int main(){
	int n;cin>>n;
	string s;cin>>s;
	vector<int> p;
	for(int i=0;i<n;i++){
		if(s[i]=='x')p.push_back(i);
	}
	int nn=p.size();
	if(nn>12)return 0;
	int ans=0;
	for(int b=0;b<(1<<nn);b++){
		for(int j=0;j<nn;j++){
			if((b>>j)&1){
				s[p[j]]='(';
			}else{
				s[p[j]]=')';
			}
		}
		vector<int> sum(n+10),mi(n+10,INF);
		mi[0]=0;
		Max seg1(n+10);
		Min seg2(n+10);
		for(int i=0;i<n;i++){
			if(s[i]=='('){
				sum[i+1]=sum[i]+1;
			}else{
				sum[i+1]=sum[i]-1;
			}
			chmin(mi[i+1],mi[i]);
			chmin(mi[i+1],sum[i+1]);
			seg1.update(i+1,sum[i+1]);
			seg2.update(i+1,sum[i+1]);
		}
		if(mi[n]==0&&sum[n]==0){
			ans++;
			continue;
		}
		if(abs(sum[n])%2)continue;
		bool f=false;
		for(int l=1;l<=n;l++){
			if(mi[l-1]<0)continue;
			for(int r=l;r<=n;r++){
				if(sum[n]/2-(sum[r]-sum[l-1])==0&&seg1.query(l,r)<=2*sum[l-1]&&seg2.query(r+1,n)-2*(sum[r]-sum[l-1])>=0){
					f=true;
					ans++;
					break;
				}
			}
			if(f)break;
		}
	}
	cout<<ans<<endl;
}
	
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 428 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 428 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 256 KB Output is correct
20 Correct 9 ms 404 KB Output is correct
21 Correct 37 ms 376 KB Output is correct
22 Correct 35 ms 256 KB Output is correct
23 Correct 4 ms 356 KB Output is correct
24 Correct 32 ms 256 KB Output is correct
25 Correct 3 ms 256 KB Output is correct
26 Correct 5 ms 256 KB Output is correct
27 Correct 42 ms 384 KB Output is correct
28 Correct 10 ms 256 KB Output is correct
29 Correct 5 ms 256 KB Output is correct
30 Correct 4 ms 256 KB Output is correct
31 Correct 29 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 428 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 256 KB Output is correct
20 Correct 9 ms 404 KB Output is correct
21 Correct 37 ms 376 KB Output is correct
22 Correct 35 ms 256 KB Output is correct
23 Correct 4 ms 356 KB Output is correct
24 Correct 32 ms 256 KB Output is correct
25 Correct 3 ms 256 KB Output is correct
26 Correct 5 ms 256 KB Output is correct
27 Correct 42 ms 384 KB Output is correct
28 Correct 10 ms 256 KB Output is correct
29 Correct 5 ms 256 KB Output is correct
30 Correct 4 ms 256 KB Output is correct
31 Correct 29 ms 256 KB Output is correct
32 Incorrect 2 ms 384 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 428 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 256 KB Output is correct
20 Correct 9 ms 404 KB Output is correct
21 Correct 37 ms 376 KB Output is correct
22 Correct 35 ms 256 KB Output is correct
23 Correct 4 ms 356 KB Output is correct
24 Correct 32 ms 256 KB Output is correct
25 Correct 3 ms 256 KB Output is correct
26 Correct 5 ms 256 KB Output is correct
27 Correct 42 ms 384 KB Output is correct
28 Correct 10 ms 256 KB Output is correct
29 Correct 5 ms 256 KB Output is correct
30 Correct 4 ms 256 KB Output is correct
31 Correct 29 ms 256 KB Output is correct
32 Incorrect 2 ms 384 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 428 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 256 KB Output is correct
20 Correct 9 ms 404 KB Output is correct
21 Correct 37 ms 376 KB Output is correct
22 Correct 35 ms 256 KB Output is correct
23 Correct 4 ms 356 KB Output is correct
24 Correct 32 ms 256 KB Output is correct
25 Correct 3 ms 256 KB Output is correct
26 Correct 5 ms 256 KB Output is correct
27 Correct 42 ms 384 KB Output is correct
28 Correct 10 ms 256 KB Output is correct
29 Correct 5 ms 256 KB Output is correct
30 Correct 4 ms 256 KB Output is correct
31 Correct 29 ms 256 KB Output is correct
32 Incorrect 2 ms 384 KB Output isn't correct
33 Halted 0 ms 0 KB -