Submission #465174

# Submission time Handle Problem Language Result Execution time Memory
465174 2021-08-15T09:45:55 Z ardaak33 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
0 / 100
2 ms 292 KB
#include <bits/stdc++.h>
using namespace std;
int sonuc=0;
int sonuc2=0;
int main() {
int n;
string s;
cin >> n >> s;
string bas=s;
int r=0,g=0;

for (int i = 0; i < n; i++)
{
    if(s[i]=='R')
    r++;
    else
    g++;
}
if(abs(r-g)>1){
cout << "-1";
return 0;
}

for (int i = 0; i < n; i++)
{
    if((!(i % 2)) and s[i]=='R' ){
    
    for (int j = i+1; j < n; j++){
    if(s[j]=='G'){
    swap(s[j],s[i]);
    sonuc+=j-i;
    break;
    }
    }
    }

    if((i % 2) and s[i]=='G' ){
    
    for (int j = i+1; j < n; j++){
    if(s[j]=='R'){
    swap(s[j],s[i]);
    sonuc+=j-i;
    break;
    }
    }
    }

}

s=bas;

for (int i = 0; i < n; i++)
{
    if((!(i % 2)) and s[i]=='G' ){
    
    for (int j = i+1; j < n; j++){
      //  cout << s[i]<< i <<s[j]<< j <<endl;

    if(s[j]=='R'){
    swap(s[j],s[i]);
    sonuc2+=j-i;
    break;
    }
    }
    }

    if((i % 2) and s[i]=='R' ){
    
    for (int j = i+1; j < n; j++){
      //  cout << s[i]<< i <<s[j]<< j <<endl;

    if(s[j]=='G'){
    swap(s[j],s[i]);
    sonuc2+=j-i;
    break;
    }
    }
    }

}
//cout <<sonuc << sonuc2 <<endl;
cout << min(sonuc,sonuc2);



}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 272 KB Output is correct
2 Correct 2 ms 272 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 272 KB Output is correct
2 Correct 2 ms 272 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 272 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 272 KB Output is correct
2 Correct 2 ms 272 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -