# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
781743 | vjudge1 | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 1 ms | 320 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);
#define OYY 1000000005
#define mod 998244353
#define mid (start+end)/2
vector <int> v,v2;
int32_t main(){
faster
int n;cin>>n;
int r=0,g=0,sr=0,sg=0;
string s;cin>>s;
for(int i=0;i<n;i++){
if(s[i]=='R')sr++;
else sg++;
}
////////////////////////////
if(n%2==0 && (sr!=sg)){
cout<<-1<<'\n';
return 0;
}
if(n%2==1 && !(sr+1==sg || sg+1==sr)){
cout<<-1<<'\n';
return 0;
}
for(int i=0;i<n;i++){
if(s[i]=='R'){
v.push_back(i);
}
else v2.push_back(i);
}
/////////////////////////////////
int cev=0;
for(int i=0;i<min(v.size(),v2.size());i++){
cev+=abs(v[i]-v2[i])-1;
}
if(n%2==0)cout<<cev<<'\n';
else{
if(sr<sg){
if(s[0]=='G' && s[n-1]=='G')cout<<cev<<'\n';
else cout<<cev+1<<'\n';
}
else{
if(s[0]=='R' && s[n-1]=='R')cout<<cev<<'\n';
else cout<<cev+1<<'\n';
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |