Submission #781746

#TimeUsernameProblemLanguageResultExecution timeMemory
781746vjudge1Growing Vegetable is Fun 3 (JOI19_ho_t3)C++17
0 / 100
1 ms212 KiB
#include<bits/stdc++.h> using namespace std; #define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define endl "\n" #define ll long long #define pb push_back #define N 200005 int n; int arr[N]; int main(){ lalala; cin>>n; string str;cin>>str; int r=0,g=0; for(int i=0;i<n;i++){ if(str[i]=='G'){ arr[i]=1;g++;} if(str[i]=='R'){ arr[i]=2;r++;} } if(abs(g-r)>1){ cout<<-1<<endl; return 0; } int aaa[n],bbb[n]; for(int i=0;i<n;i++){ if(i%2){ aaa[i]=2;bbb[i]=1; } else {aaa[i]=1;bbb[i]=2;} } ll int cev1=1000000000,cev2=1000000000; if(r-g>-1){ cev1=0; for(int i=0;i<n;i++){ if(arr[i]!=aaa[i]){ for(int j=i+1;j<n;j++){ if(arr[j]==aaa[i]&&aaa[j]!=arr[j]){ cev1+=(j-i); swap(arr[j],arr[i]); break; } } } } } if(g-r>-1){ cev2=0; for(int i=0;i<n;i++){ if(arr[i]!=bbb[i]){ for(int j=i+1;j<n;j++){ if(arr[j]==bbb[i]&&bbb[j]!=arr[j]){ cev2+=(j-i); swap(arr[j],arr[i]); break; } } } } } cev1=min(cev1,cev2); cout<<cev1<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...