Submission #1089377

#TimeUsernameProblemLanguageResultExecution timeMemory
1089377vjudge1Growing Vegetable is Fun 3 (JOI19_ho_t3)C++17
0 / 100
0 ms452 KiB
#include <bits/stdc++.h> //qwerty47924692 using namespace std; using ll = long long; #define f first #define s second const ll N=3e5+29; ll cur1,cur2,cnt[2],n; string s; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>s; for(char i:s){ if(i=='G')cnt[0]++; else cnt[1]++; } ll ans=1e18; if(abs(cnt[1]-cnt[0])>1){ cout<<-1; return 0; } if(cnt[1]>=cnt[0]){ cur1=0; cur2=1; ll sum=0; for(ll i=0;i<n;i++){ if(s[i]=='R'){ sum+=abs(i-cur1); cur1+=2; } else{ sum+=abs(i-cur2); cur2+=2; } } ans=min(ans,sum); } if(cnt[1]<=cnt[0]){ cur1=1; cur2=0; ll sum=0; for(ll i=0;i<n;i++){ if(s[i]=='R'){ sum+=abs(i-cur1); cout<<cur1<<' '; cur1+=2; } else{ sum+=abs(i-cur2); cout<<cur2<<' '; cur2+=2; } } ans=min(ans,sum); } cout<<ans/2; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...