제출 #97516

#제출 시각아이디문제언어결과실행 시간메모리
97516dalgerokGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
0 / 100
701 ms780536 KiB
#include<bits/stdc++.h>
using namespace std;



const int N = 405;


int n, cnt[N][3], pos[3][N];
char a[N];
int dp[N][N][N][3];

inline void upd(int &x, int y){
    if(x > y){
        x = y;
    }
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        char c;
        cin >> c;
        if(c == 'R'){
            a[i] = 0;
        }
        else if(c =='G'){
            a[i] = 1;
        }
        else{
            a[i] = 2;
        }
        for(int j = 0; j < 3; j++){
            cnt[i][j] = cnt[i - 1][j];
        }
        cnt[i][a[i]] += 1;
        pos[a[i]][cnt[i][a[i]]] = i;
    }
    memset(dp, 63, sizeof(dp));
    dp[0][0][0][0] = dp[0][0][0][1] = dp[0][0][0][2] = 0;
    for(int i = 0; i <= cnt[n][0]; i++){
        for(int j = 0; j <= cnt[n][1]; j++){
            for(int k = 0; k <= cnt[n][2]; k++){
                for(int d = 0; d < 3; d++){
                    int p;
                    if(d != 0 && i + 1 <= cnt[n][0]){
                        p = pos[0][i + 1];
                        upd(dp[i + 1][j][k][0], dp[i][j][k][d] + max(0, cnt[p][1] - j) + max(0, cnt[p][2] - k));
                    }
                    if(d != 1 && j + 1 <= cnt[n][1]){
                        p = pos[1][j + 1];
                        upd(dp[i][j + 1][k][1], dp[i][j][k][d] + max(0, cnt[p][0] - i) + max(0, cnt[p][2] - k));
                    }
                    if(d != 2 && k + 1 <= cnt[n][2]){
                        p = pos[2][k + 1];
                        upd(dp[i][j][k + 1][2], dp[i][j][k][d] + max(0, cnt[p][0] - i) + max(0, cnt[p][1] - j));
                    }
                }
            }
        }
    }
    int ans = 2e9;
    for(int i = 0; i < 3; i++){
        upd(ans, dp[cnt[n][0]][cnt[n][1]][cnt[n][2]][i]);
    }
    if(ans > 1e7){
        return cout << "-1", 0;
    }
    cout << ans;
}

컴파일 시 표준 에러 (stderr) 메시지

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:37:20: warning: array subscript has type 'char' [-Wchar-subscripts]
         cnt[i][a[i]] += 1;
                    ^
joi2019_ho_t3.cpp:38:17: warning: array subscript has type 'char' [-Wchar-subscripts]
         pos[a[i]][cnt[i][a[i]]] = i;
                 ^
joi2019_ho_t3.cpp:38:30: warning: array subscript has type 'char' [-Wchar-subscripts]
         pos[a[i]][cnt[i][a[i]]] = i;
                              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...