답안 #929020

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
929020 2024-02-17T13:39:01 Z salmon Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

int N;
int memo[3][410][410][410];
int rp[410],gp[410],yp[410];
int R;
int G;
int Y;
char lst[410];
const int inf = 1100100100;
bool visited[410];

int root[3][410];


int main(){
    scanf(" %d",&N);

    for(int i = 0; i < N; i++){
        scanf(" %c",&lst[i]);

        if(lst[i] == 'R'){
            R++;
        }
        else if(lst[i] == 'G'){
            G++;
        }
        else if(lst[i] == 'Y'){
            Y++;
        }
    }

    memo[0][R][G][Y] = 0;
    memo[1][R][G][Y] = 0;
    memo[2][R][G][Y] = 0;

    int it = 0;
    for(int i = 0; i < N; i++){
        if(lst[i] == 'R'){
            rp[it] = i;
            it++;
        }
    }

    it = 0;
    for(int i = 0; i < N; i++){
        if(lst[i] == 'G'){
            gp[it] = i;
            it++;
        }
    }

    it = 0;
    for(int i = 0; i < N; i++){
        if(lst[i] == 'Y'){
            yp[it] = i;
            it++;
        }
    }

    for(int i = 0; i <= N; i++){
        root[0][R][i] = 0;
        root[0][G][i] = 0;
        root[0][Y][i] = 0;
    }

    for(int r = R - 1; r >= 0; r--){
        for(int i = 0; i <= N; i++){
            root[0][r][i] = root[0][r + 1][i];
            if(i >= rp[r]) root[0][r][i]++;
        }
    }

    for(int g = G - 1; g >= 0; g--){
        for(int i = 0; i <= N; i++){
            root[1][g][i] = root[1][g + 1][i];
            if(i >= gp[g]) root[1][g][i]++;
        }
    }

    for(int y = Y - 1; y >= 0; y--){
        for(int i = 0; i <= N; i++){
            root[2][y][i] = root[2][y + 1][i];
            if(i >= yp[y]) root[2][y][i]++;
        }
    }

    for(int i = N - 1; i >= 0; i--){
        for(int r = 0; r <= min(R,i); r++){
            for(int g = 0; g <= min(G,i - r); g++){
                y = i - r - g;
                    int j = r + g + y;

                    if(r == R || min(memo[1][r + 1][g][y], memo[2][r + 1][g][y]) == inf){
                        memo[0][r][g][y] = inf;
                    }
                    else{
                        memo[0][r][g][y] = min(memo[1][r + 1][g][y], memo[2][r + 1][g][y]) + j-rp[r]+root[0][r+1][rp[r]] + root[1][g][rp[r]] + root[2][y][rp[r]];
                    }

                    if(g == G || min(memo[0][r][g + 1][y], memo[2][r][g + 1][y]) == inf){
                        memo[1][r][g][y] = inf;
                    }
                    else{
                        memo[1][r][g][y] = min(memo[0][r][g + 1][y], memo[2][r][g + 1][y])+ j-gp[g]+root[0][r][gp[g]] + root[1][g+1][gp[g]] + root[2][y][gp[g]];
                    }

                    if(y == Y || min(memo[0][r][g][y + 1], memo[1][r][g][y + 1]) == inf){
                        memo[2][r][g][y] = inf;
                    }
                    else{
                        memo[2][r][g][y] = min(memo[0][r][g][y + 1], memo[1][r][g][y + 1])+ j-yp[y]+root[0][r][yp[y]] + root[1][g][yp[y]] + root[2][y+1][yp[y]];
                    }
            }
        }
    }

    if(min(memo[0][0][0][0],min(memo[1][0][0][0],memo[2][0][0][0])) != inf){
        printf("%d",min(memo[0][0][0][0],min(memo[1][0][0][0],memo[2][0][0][0])));
    }
    else{
        printf("-1");
    }

}
/*
6
GGGGRRR
GRGRGRG

RGRGYG
*/

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:63:19: error: invalid types 'int[int]' for array subscript
   63 |         root[0][R][i] = 0;
      |                   ^
joi2019_ho_t3.cpp:64:19: error: invalid types 'int[int]' for array subscript
   64 |         root[0][G][i] = 0;
      |                   ^
joi2019_ho_t3.cpp:65:19: error: invalid types 'int[int]' for array subscript
   65 |         root[0][Y][i] = 0;
      |                   ^
joi2019_ho_t3.cpp:70:23: error: invalid types 'int[int]' for array subscript
   70 |             root[0][r][i] = root[0][r + 1][i];
      |                       ^
joi2019_ho_t3.cpp:70:43: error: invalid types 'int[int]' for array subscript
   70 |             root[0][r][i] = root[0][r + 1][i];
      |                                           ^
joi2019_ho_t3.cpp:71:38: error: invalid types 'int[int]' for array subscript
   71 |             if(i >= rp[r]) root[0][r][i]++;
      |                                      ^
joi2019_ho_t3.cpp:77:23: error: invalid types 'int[int]' for array subscript
   77 |             root[1][g][i] = root[1][g + 1][i];
      |                       ^
joi2019_ho_t3.cpp:77:43: error: invalid types 'int[int]' for array subscript
   77 |             root[1][g][i] = root[1][g + 1][i];
      |                                           ^
joi2019_ho_t3.cpp:78:38: error: invalid types 'int[int]' for array subscript
   78 |             if(i >= gp[g]) root[1][g][i]++;
      |                                      ^
joi2019_ho_t3.cpp:84:23: error: invalid types 'int[int]' for array subscript
   84 |             root[2][y][i] = root[2][y + 1][i];
      |                       ^
joi2019_ho_t3.cpp:84:43: error: invalid types 'int[int]' for array subscript
   84 |             root[2][y][i] = root[2][y + 1][i];
      |                                           ^
joi2019_ho_t3.cpp:85:38: error: invalid types 'int[int]' for array subscript
   85 |             if(i >= yp[y]) root[2][y][i]++;
      |                                      ^
joi2019_ho_t3.cpp:92:17: error: 'y' was not declared in this scope
   92 |                 y = i - r - g;
      |                 ^
joi2019_ho_t3.cpp:99:114: error: invalid types 'int[int]' for array subscript
   99 |                         memo[0][r][g][y] = min(memo[1][r + 1][g][y], memo[2][r + 1][g][y]) + j-rp[r]+root[0][r+1][rp[r]] + root[1][g][rp[r]] + root[2][y][rp[r]];
      |                                                                                                                  ^
joi2019_ho_t3.cpp:99:134: error: invalid types 'int[int]' for array subscript
   99 |                         memo[0][r][g][y] = min(memo[1][r + 1][g][y], memo[2][r + 1][g][y]) + j-rp[r]+root[0][r+1][rp[r]] + root[1][g][rp[r]] + root[2][y][rp[r]];
      |                                                                                                                                      ^
joi2019_ho_t3.cpp:106:111: error: invalid types 'int[int]' for array subscript
  106 |                         memo[1][r][g][y] = min(memo[0][r][g + 1][y], memo[2][r][g + 1][y])+ j-gp[g]+root[0][r][gp[g]] + root[1][g+1][gp[g]] + root[2][y][gp[g]];
      |                                                                                                               ^
joi2019_ho_t3.cpp:106:133: error: invalid types 'int[int]' for array subscript
  106 |                         memo[1][r][g][y] = min(memo[0][r][g + 1][y], memo[2][r][g + 1][y])+ j-gp[g]+root[0][r][gp[g]] + root[1][g+1][gp[g]] + root[2][y][gp[g]];
      |                                                                                                                                     ^
joi2019_ho_t3.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf(" %d",&N);
      |     ~~~~~^~~~~~~~~~
joi2019_ho_t3.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf(" %c",&lst[i]);
      |         ~~~~~^~~~~~~~~~~~~~~