# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
130164 | dragonslayerit | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 1052 ms | 2716 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <vector>
#include <algorithm>
int N;
char str[100005];
std::vector<int> where[100005];
const char rgy[]="RGY";
char ts[100005];
int main(){
scanf("%d %s",&N,str);
for(int i=0;i<N;i++){
where[std::find(rgy,rgy+3,str[i])-rgy].push_back(i);
}
std::copy(str,str+N,ts);
std::sort(ts,ts+N);
int best=1e9;
do{
int ind[3]={0,0,0};
int cost=0;
bool bad=false;
for(int i=1;i<N;i++){
if(ts[i]==ts[i-1]) bad=true;
}
if(bad) continue;
for(int i=0;i<N;i++){
int c=std::find(rgy,rgy+3,ts[i])-rgy;
cost+=std::max(0,i-where[c][ind[c]++]);
}
best=std::min(best,cost);
}while(std::next_permutation(ts,ts+N));
printf("%d\n",best<1e9?best:-1);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |