Submission #234877

#TimeUsernameProblemLanguageResultExecution timeMemory
234877wiwihoGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
100 / 100
182 ms2844 KiB
//#define NDEBUG #include <bits/stdc++.h> #include <bits/extc++.h> #define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define iter(a) a.begin(), a.end() #define riter(a) a.rbegin(), a.rend() #define lsort(a) sort(iter(a)) #define gsort(a) sort(riter(a)) #define mp(a, b) make_pair(a, b) #define pb(a) push_back(a) #define eb(a) emplace_back(a) #define pf(a) push_front(a) #define pob pop_back() #define pof pop_front() #define F first #define S second #define printv(a, b) {bool pvaspace=false; \ for(auto pva : a){ \ if(pvaspace) b << " "; pvaspace=true;\ b << pva;\ }\ b << "\n";} #define pii pair<int, int> #define pll pair<ll, ll> #define tiii tuple<int, int, int> #define mt make_tuple #define gt(t, i) get<i>(t) #define iceil(a, b) ((a) / (b) + !!((a) % (b))) //#define TEST typedef long long ll; typedef unsigned long long ull; using namespace std; using namespace __gnu_pbds; const ll MOD = 1000000007; const ll MAX = 2147483647; template<typename A, typename B> ostream &operator<<(ostream &o, pair<A, B> p){ return o << '(' << p.F << ',' << p.S << ')'; } int main(){ StarBurstStream int n; cin >> n; string s; cin >> s; vector<int> rp, gp, yp; vector<int> rc(n), gc(n), yc(n); for(int i = 0; i < n; i++){ if(s[i] == 'R') rp.eb(i), rc[i]++; else if(s[i] == 'G') gp.eb(i), gc[i]++; else yp.eb(i), yc[i]++; if(i) rc[i] += rc[i - 1], gc[i] += gc[i - 1], yc[i] += yc[i - 1]; } vector<vector<ll>> dpr(rp.size() + 1, vector<ll>(gp.size() + 1, MAX)); vector<vector<ll>> dpg(rp.size() + 1, vector<ll>(gp.size() + 1, MAX)); vector<vector<ll>> dpy(rp.size() + 1, vector<ll>(gp.size() + 1, MAX)); dpr[0][0] = 0; dpg[0][0] = 0; dpy[0][0] = 0; for(int i = 1; i <= n; i++){ vector<vector<ll>> dpr2(rp.size() + 1, vector<ll>(gp.size() + 1, MAX)); vector<vector<ll>> dpg2(rp.size() + 1, vector<ll>(gp.size() + 1, MAX)); vector<vector<ll>> dpy2(rp.size() + 1, vector<ll>(gp.size() + 1, MAX)); for(int r = 0; r <= i && r <= rp.size(); r++){ for(int g = 0; r + g <= i && g <= gp.size(); g++){ int y = i - r - g; if(y > yp.size()) continue; if(r) dpr2[r][g] = min(dpg[r - 1][g] + max(0, gc[rp[r - 1]] - g) + max(0, yc[rp[r - 1]] - y), dpy[r - 1][g] + max(0, gc[rp[r - 1]] - g) + max(0, yc[rp[r - 1]] - y)); if(g) dpg2[r][g] = min(dpr[r][g - 1] + max(0, yc[gp[g - 1]] - y) + max(0, rc[gp[g - 1]] - r), dpy[r][g - 1] + max(0, yc[gp[g - 1]] - y) + max(0, rc[gp[g - 1]] - r)); if(y) dpy2[r][g] = min(dpr[r][g] + max(0, rc[yp[y - 1]] - r) + max(0, gc[yp[y - 1]] - g), dpg[r][g] + max(0, rc[yp[y - 1]] - r) + max(0, gc[yp[y - 1]] - g)); } } dpr = dpr2; dpg = dpg2; dpy = dpy2; } if(min({dpr[rp.size()][gp.size()], dpg[rp.size()][gp.size()], dpy[rp.size()][gp.size()]}) >= MAX) cout << "-1\n"; else cout << min({dpr[rp.size()][gp.size()], dpg[rp.size()][gp.size()], dpy[rp.size()][gp.size()]}) << "\n"; return 0; }

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:78:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int r = 0; r <= i && r <= rp.size(); r++){
                                  ~~^~~~~~~~~~~~
joi2019_ho_t3.cpp:79:44: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int g = 0; r + g <= i && g <= gp.size(); g++){
                                          ~~^~~~~~~~~~~~
joi2019_ho_t3.cpp:81:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(y > yp.size()) continue;
                    ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...