답안 #128448

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128448 2019-07-10T23:28:02 Z dragonslayerit Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
15 / 100
136 ms 163072 KB
#include <cstdio>
#include <algorithm>
#include <vector>

const int INF=1e9+7;

int dp[401][401][401][3];

std::vector<int> where[3];

char rgy[]="RGY";

int N;
char str[405];

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+1);
  }
  for(int a=0;a<=where[0].size();a++){
    for(int b=0;b<=where[1].size();b++){
      for(int c=0;c<=where[2].size();c++){
	std::fill(dp[a][b][c],dp[a][b][c]+3,(a+b+c==0)?0:INF);
	if(a) dp[a][b][c][0]=std::abs(a+b+c-where[0][a-1])+std::min(dp[a-1][b][c][1],dp[a-1][b][c][2]);
	if(b) dp[a][b][c][1]=std::abs(a+b+c-where[1][b-1])+std::min(dp[a][b-1][c][2],dp[a][b-1][c][0]);
	if(c) dp[a][b][c][2]=std::abs(a+b+c-where[2][c-1])+std::min(dp[a][b][c-1][0],dp[a][b][c-1][1]);
	//auto x=dp[a][b][c];
	//printf("dp[%d][%d][%d]: %d %d %d\n",a,b,c,x[0],x[1],x[2]);
      }
    }
  }
  auto x=dp[where[0].size()][where[1].size()][where[2].size()];
  int ans=*std::min_element(x,x+3);
  printf("%d\n",ans<INF?ans/2:-1);
  return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:21:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int a=0;a<=where[0].size();a++){
               ~^~~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:22:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int b=0;b<=where[1].size();b++){
                 ~^~~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:23:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int c=0;c<=where[2].size();c++){
                   ~^~~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %s",&N,str);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 292 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Incorrect 2 ms 504 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 292 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Incorrect 2 ms 504 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 122 ms 162924 KB Output is correct
3 Correct 121 ms 162144 KB Output is correct
4 Correct 122 ms 162956 KB Output is correct
5 Correct 125 ms 162936 KB Output is correct
6 Correct 123 ms 162952 KB Output is correct
7 Correct 123 ms 162208 KB Output is correct
8 Correct 122 ms 162092 KB Output is correct
9 Correct 123 ms 161388 KB Output is correct
10 Correct 124 ms 162912 KB Output is correct
11 Correct 122 ms 162936 KB Output is correct
12 Correct 35 ms 44028 KB Output is correct
13 Correct 59 ms 77176 KB Output is correct
14 Correct 83 ms 111352 KB Output is correct
15 Correct 136 ms 163072 KB Output is correct
16 Correct 124 ms 162904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 292 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Incorrect 2 ms 504 KB Output isn't correct
12 Halted 0 ms 0 KB -