Submission #292587

# Submission time Handle Problem Language Result Execution time Memory
292587 2020-09-07T10:15:30 Z kshitij_sodani Monochrome Points (JOI20_monochrome) C++14
35 / 100
2000 ms 15504 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
//#define endl '\n' 


int n;
vector<int> aa;
vector<int> bb;
bool sect(int cc,int dd,int ee,int ff){
	if(cc>dd){
		swap(cc,dd);
	}
	if(ee>ff){
		swap(ee,ff);
	}
	if(cc>ee){
		swap(cc,ee);
		swap(dd,ff);
	}


	if(cc<=ee and ee<=dd and dd<=ff){
		return true;
	}

	return false;
}
int tree[400001];
int vis[400001];
void u(int i,int j){
	while(i<400001){
		tree[i]+=j;
		i+=(i&-i);
	}
}
int stt(int i){
	int su=0;
	while(i>0){
		su+=tree[i];
		i-=(i&-i);
	}
	return su;
}
llo vis2[200001];
llo val(int ii){
	if(vis2[ii]>-1){
		return vis2[ii];
	}
	vector<int> ss;
	for(int i=ii;i<n;i++){
		ss.pb(bb[i]);
	}
	for(int i=0;i<ii;i++){
		ss.pb(bb[i]);
	}
	llo co=0;
	vector<pair<int,int>> mm;
	for(int i=0;i<n;i++){
		mm.pb({aa[i],i});
		mm.pb({ss[i],i});
	}
	for(int j=0;j<2*n;j++){
		tree[j+1]=0;
		vis[j]=0;
	}
	sort(mm.begin(),mm.end());
	for(auto j:mm){
		if(vis[j.b]){
			co+=stt(j.a+1)-stt(vis[j.b]+1);
			u(vis[j.b]+1,-1);
		}
		else{
			vis[j.b]=j.a;
			u(j.a+1,1);
		}
	}
	vis2[ii]=co;
	return co;




}
llo cal(int  x,int y){
	int low=x;
	int high=y;
	while(low<high-1){
		int mid=(low+high)/2;
		int xx=val(mid);
		int yy=val(mid+1);
		if(xx<yy){
			low=mid+1;
		}
		else{
			high=mid;
		}
	}
	llo ma=0;
	for(int i=low;i<=high;i++){
		ma=max(ma,val(i));
	}





	return ma;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
		for(int i=0;i<n;i++){
			vis2[i]=-1;
		}

	for(int i=0;i<2*n;i++){
		char cc;
		cin>>cc;
		if(cc=='B'){
			aa.pb(i);
		}	
		else{
			bb.pb(i);
		}
	}
	/*if(n>10){
		return 0;
	}*/
	vector<int> ss;
	for(auto j:bb){
		ss.pb(j);
	}
	llo ans=0;
	/*vector<int> pp;
	for(int jj=0;jj<n;jj++){
		ans=max(ans,val(jj));
	}*/
	ans=val(n-1);
	llo xx=val(0);
	llo ans2=0;
	

	if(xx<ans){
		int low=0;
		int high=n-1;
		while(low<high-1){
			int mid=(low+high)/2;
			if(val(mid)<ans){
				low=mid+1;
			}
			else{
				high=mid;
			}
		}
		int ind=high;
		if(val(low)>=ans){
			ind=min(ind,low);
		}
		ans2=max(ans2,cal(ind,n-1));
/*	for(int j=ind;j<n;j++){
		ans=max(ans,val(j));
	}*/
   	 }
   	 if(xx>=ans){
   	 	int low=0;
		int high=n-1;
		while(low<high-1){
			int mid=(low+high)/2;
			if(val(mid)>=ans){
				low=mid;
			}
			else{
				high=mid;
			}
		}
		int ind=low;
		if(val(high)>=ans){
			ind=max(ind,high);
		}
	/*	for(int i=0;i<=ind;i++){
			ans=max(ans,val(i));
		}*/
		ans2=max(ans2,(cal(0,ind)));
   	 }


	/*int pop=0;
	for(int ii=0;ii<n;ii++){
		vector<int> tt;
		for(int j=ii;j<n;j++){
			tt.pb(pp[j]);
		}
		for(int j=0;j<ii;j++){
			tt.pb(pp[j]);
		}
		int kk=1;
		for(int i=1;i<n-1;i++){
			if(tt[i]<tt[i+1] and tt[i]<tt[i-1]){
				kk=0;
			}
		}
		for(int i=0;i<n;i++){
			if(tt[i]==tt[(i+1)%n]){
				kk=0;
			}
		}

		pop=max(pop,kk);


	}*/
/*	if(pop==0){
		while(true){
			continue;
		}
	}*/
	cout<<ans2<<endl;
	/*for(auto j:pp){
		cout<<j<<",";
	}
	cout<<endl;*/



	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 2 ms 360 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 2 ms 360 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 14 ms 512 KB Output is correct
35 Correct 14 ms 512 KB Output is correct
36 Correct 16 ms 512 KB Output is correct
37 Correct 14 ms 512 KB Output is correct
38 Correct 13 ms 584 KB Output is correct
39 Correct 12 ms 512 KB Output is correct
40 Correct 11 ms 512 KB Output is correct
41 Correct 11 ms 512 KB Output is correct
42 Correct 13 ms 512 KB Output is correct
43 Correct 12 ms 512 KB Output is correct
44 Correct 12 ms 512 KB Output is correct
45 Correct 10 ms 512 KB Output is correct
46 Correct 13 ms 512 KB Output is correct
47 Correct 11 ms 512 KB Output is correct
48 Correct 13 ms 512 KB Output is correct
49 Correct 11 ms 512 KB Output is correct
50 Correct 6 ms 512 KB Output is correct
51 Correct 5 ms 512 KB Output is correct
52 Correct 14 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 2 ms 360 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 14 ms 512 KB Output is correct
35 Correct 14 ms 512 KB Output is correct
36 Correct 16 ms 512 KB Output is correct
37 Correct 14 ms 512 KB Output is correct
38 Correct 13 ms 584 KB Output is correct
39 Correct 12 ms 512 KB Output is correct
40 Correct 11 ms 512 KB Output is correct
41 Correct 11 ms 512 KB Output is correct
42 Correct 13 ms 512 KB Output is correct
43 Correct 12 ms 512 KB Output is correct
44 Correct 12 ms 512 KB Output is correct
45 Correct 10 ms 512 KB Output is correct
46 Correct 13 ms 512 KB Output is correct
47 Correct 11 ms 512 KB Output is correct
48 Correct 13 ms 512 KB Output is correct
49 Correct 11 ms 512 KB Output is correct
50 Correct 6 ms 512 KB Output is correct
51 Correct 5 ms 512 KB Output is correct
52 Correct 14 ms 512 KB Output is correct
53 Execution timed out 2065 ms 15504 KB Time limit exceeded
54 Halted 0 ms 0 KB -