# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110424 | Leonardo_Paes | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++11 | 3 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;
string s1=s, s2=s;
for(int i=0; i<s1.size(); i++){
if(i%2==0 and s1[i]=='B'){
for(int j=i; j<s1.size(); j++){
if(i%2==1 and s1[j]=='A'){
s1[i]='A';
s1[j]='B';
resp1+=j-i;
break;
}
}
if(s1[i]=='B')res1=false;
}
else if(i%2==1 and s1[i]=='A'){
for(int j=i; j<s1.size(); j++){
if(j%2==0 and s1[j]=='B'){
s1[i]='B';
s1[j]='A';
resp1+=j-i;
break;
}
}
if(s1[i]=='A')res1=false;
}
}
for(int i=0; i<s2.size(); i++){
if(i%2==0 and s2[i]=='A'){
for(int j=i; j<s2.size(); j++){
if(j%2==1 and s2[j]=='B'){
s2[i]='B';
s2[j]='A';
resp2+=j-i;
break;
}
}
if(s2[i]=='A')res2=false;
}
else if(i%2==1 and s2[i]=='B'){
for(int j=i; j<s2.size(); j++){
if(j%2==0 and s2[j]=='A'){
s2[i]='A';
s2[j]='B';
resp2+=j-i;
break;
}
}
if(s2[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... |