제출 #97519

#제출 시각아이디문제언어결과실행 시간메모리
97519dalgerokGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++17
0 / 100
864 ms780684 KiB
#include<bits/stdc++.h> using namespace std; const int N = 405; int n, cnt[N][3], pos[N][3]; 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[cnt[i][a[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[i + 1][0]; 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[j + 1][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[k + 1][2]; 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:24: warning: array subscript has type 'char' [-Wchar-subscripts]
         pos[cnt[i][a[i]]][a[i]] = i;
                        ^
joi2019_ho_t3.cpp:38:31: warning: array subscript has type 'char' [-Wchar-subscripts]
         pos[cnt[i][a[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...