제출 #710383

#제출 시각아이디문제언어결과실행 시간메모리
710383lukameladzeGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
100 / 100
118 ms165300 KiB
# include <bits/stdc++.h> using namespace std; #define f first #define s second //#define int long long #define pii pair <int, int> #define pb push_back const int N = 401, inf = 1e9; int t,n,a[N], dp[N][N][N][3],pr[N][3], cnt[3]; bool fix[N][N][N][3]; string s; vector <int> vec[3]; int get_cnt(int le, int ri, int ty) { if (le > ri) return 0; return pr[ri][ty] - pr[le - 1][ty]; } int get(int i, int j, int k, int ty) { //cout<<"get "<<i<<" "<<j<<" "<<k<<" "<<ty<<"\n"; if (ty == 0) { return get_cnt(vec[1][j] + 1, vec[0][i], 1) + get_cnt(vec[2][k] + 1, vec[0][i], 2); } if (ty == 1) { return get_cnt(vec[0][i] + 1, vec[1][j], 0) + get_cnt(vec[2][k] + 1, vec[1][j], 2); } if (ty == 2) { return get_cnt(vec[0][i] + 1, vec[2][k], 0) + get_cnt(vec[1][j] + 1, vec[2][k], 1); } } main() { std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>n>>s; s = "@" + s; for (int i = 0; i < 3; i++) { vec[i].pb(0); } for (int i = 1; i <= n; i++) { if (s[i] == 'R') s[i] = 'a'; else s[i] = (s[i] == 'G' ? 'b' : 'c'); vec[s[i] - 'a'].pb(i); cnt[s[i] - 'a']++; for (int j = 0; j < 3; j++) { pr[i][j] += pr[i - 1][j]; } pr[i][s[i] - 'a']++; } for (int i = 0; i <= cnt[0]; i++) { for (int j = 0; j <= cnt[1]; j++) { for (int k = 0; k <= cnt[2]; k++) { for (int lst = 0; lst <= 2; lst++) { dp[i][j][k][lst] = inf; if (i + j + k == 0) { dp[i][j][k][lst] = 0; fix[i][j][k][lst] = -1; } } } } } for (int i = 0; i <= cnt[0]; i++) { for (int j = 0; j <= cnt[1]; j++) { for (int k = 0; k <= cnt[2]; k++) { for (int pr_lst = 0; pr_lst <= 2; pr_lst++) { if (!fix[i][j][k][pr_lst]) continue; if (i < cnt[0] && pr_lst != 0) { dp[i + 1][j][k][0] = min(dp[i + 1][j][k][0], dp[i][j][k][pr_lst] + get(i + 1, j, k, 0)); fix[i + 1][j][k][0] = 1; } if (j < cnt[1] && pr_lst != 1) { dp[i][j + 1][k][1] = min(dp[i][j + 1][k][1], dp[i][j][k][pr_lst] + get(i, j + 1, k, 1)); fix[i][j + 1][k][1] = 1; } if (k < cnt[2] && pr_lst != 2) { dp[i][j][k + 1][2] = min(dp[i][j][k + 1][2], dp[i][j][k][pr_lst] + get(i, j, k + 1, 2)); fix[i][j][k + 1][2] = 1; } } } } } int mn = min(dp[cnt[0]][cnt[1]][cnt[2]][0], dp[cnt[0]][cnt[1]][cnt[2]][1]); mn = min(mn, dp[cnt[0]][cnt[1]][cnt[2]][2]); cout<<(mn == inf ? -1 : mn)<<"\n"; }

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

joi2019_ho_t3.cpp:29:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   29 | main() {
      | ^~~~
joi2019_ho_t3.cpp: In function 'int get(int, int, int, int)':
joi2019_ho_t3.cpp:28:1: warning: control reaches end of non-void function [-Wreturn-type]
   28 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...