# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
217199 | 2020-03-29T08:25:43 Z | kshitij_sodani | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 7 ms | 384 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+(n/2+1-co))-i); ind+=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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Incorrect | 4 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Incorrect | 4 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 7 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 4 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 4 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 4 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 4 ms | 384 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Incorrect | 4 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |