Submission #465174

#TimeUsernameProblemLanguageResultExecution timeMemory
465174ardaak33Growing Vegetable is Fun 3 (JOI19_ho_t3)C++17
0 / 100
2 ms292 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...