# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110423 | Leonardo_Paes | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++11 | 2 ms | 384 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;
int main(){
int n;
cin >> n;
string s;
cin >> s;
int resp1=0, resp2=0;
int r=0, g=0;
for(int i=0; i<s.size(); i++){
if(s[i]=='R')s[i]='A';
else s[i]='B';
}
bool res1=true, res2=true;
for(int i=0; i<s.size(); i++){
if(i%2==0 and s[i]=='B'){
for(int j=i; j<s.size(); j++){
if(i%2==1 and s[i]=='A'){
s[i]='A';
s[j]='B';
resp1+=j-i;
break;
}
}
if(s[i]=='B')res1=false;
}
else if(i%2==1 and s[i]=='A'){
for(int j=i; j<s.size(); j++){
if(j%2==0 and s[j]=='B'){
s[i]='B';
s[j]='A';
resp1+=j-i;
break;
}
}
if(s[i]=='A')res1=false;
}
}
for(int i=0; i<s.size(); i++){
if(i%2==0 and s[i]=='A'){
for(int j=i; j<s.size(); j++){
if(i%2==1 and s[j]=='B'){
s[i]='B';
s[j]='A';
resp2+=j-i;
break;
}
}
if(s[i]=='A')res2=false;
}
else if(i%2==1 and s[i]=='B'){
for(int j=i; j<s.size(); j++){
if(i%2==1 and s[i]=='A'){
s[i]='A';
s[j]='B';
resp2+=j-i;
break;
}
}
if(s[i]=='B')res2=false;
}
}
if(res1==true and res2==true){
cout << min(resp1, resp2) << endl;
}
else if(res1==true){
cout << resp1 << endl;
}
else if(res2==true){
cout << resp2 << endl;
}
else{
cout << -1 << endl;
}
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... |