# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
217196 | 2020-03-29T08:20:13 Z | kshitij_sodani | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 5 ms | 432 KB |
#include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long int llo; #define mp make_pair #define pb push_back #define a first #define b second #define endl "\n" llo mod=1000000007; int n; int it[401]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); //setIO(""); cin>>n; char ss; int co=0; for(int i=0;i<n;i++){ cin>>ss; if(ss=='R'){ co+=1; } else if(ss=='G'){ it[i]=1; } else{ return 0; } } if(co>(n+1)/2 or (n-co)>(n+1)/2){ cout<<-1<<endl; return 0; } if(n%2==1){ int ans=0; int ind=0; int ind2=0; for(int i=0;i<n;i++){ if(it[i]==0){ ans+=abs((ind*2+1-co%2)-i); ind+=1; } /*else{ ans+=abs((ind2*2+co%2)-i); ind2+=1; }*/ } cout<<ans<<endl; } else{ int ans=0; int ind=0; int ind2=0; for(int i=0;i<n;i++){ if(it[i]==0){ ans+=abs((ind*2)-i); ind+=1; } else{ ans+=abs((ind2*2+1)-i); ind2+=1; } } int ans2=0; ind=0; ind2=0; for(int i=0;i<n;i++){ if(it[i]==0){ ans2+=abs((ind*2+1)-i); ind+=1; } else{ ans2+=abs((ind2*2)-i); ind2+=1; } } cout<<min(ans,ans2)/2<<endl; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Incorrect | 4 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Incorrect | 4 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 432 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Incorrect | 4 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |