Submission #217195

# Submission time Handle Problem Language Result Execution time Memory
217195 2020-03-29T08:18:46 Z kshitij_sodani Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
0 / 100
500 ms 384 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl "\n"
llo mod=1000000007;
int n;
int it[401];
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	//setIO("");
	cin>>n;
	char ss;
	int co=0;

	for(int i=0;i<n;i++){
		cin>>ss;
		if(ss=='R'){
			co+=1;
		}
		else if(ss=='G'){
			it[i]=1;
		}
		else{
			return 0;
		}
	}
	if(co>(n+1)/2 or (n-co)>(n+1)/2){
		cout<<-1<<endl;
		return 0;
	}
	if(n%2==1){
		while(true){
			continue;
		}
		int ans=0;
		int ind=0;
		int ind2=0;
		for(int i=0;i<n;i++){
			if(it[i]==0){
				ans+=abs((ind*2+1-co%2)-i);
				ind+=1;
			}
			else{
				ans+=abs((ind2*2+co%2)-i);
				ind2+=1;
			}
		}
		cout<<ans/2<<endl;
	}
	else{
		int ans=0;
		int ind=0;
		int ind2=0;
		for(int i=0;i<n;i++){
			if(it[i]==0){
				ans+=abs((ind*2)-i);
				ind+=1;
			}
			else{
				ans+=abs((ind2*2+1)-i);
				ind2+=1;
			}
		}
		int ans2=0;
		ind=0;
		ind2=0;
		for(int i=0;i<n;i++){
			if(it[i]==0){
				ans2+=abs((ind*2+1)-i);
				ind+=1;
			}
			else{
				ans2+=abs((ind2*2)-i);
				ind2+=1;
			}
		}
		cout<<min(ans,ans2)/2<<endl;
	}




	













	return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -