Submission #97445

#TimeUsernameProblemLanguageResultExecution timeMemory
97445polyfishGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
15 / 100
3 ms384 KiB
//Pantyhose(black) + glasses = infinity #include <bits/stdc++.h> using namespace std; #define debug(x) cerr << #x << " = " << x << '\n'; #define BP() cerr << "OK!\n"; #define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';} #define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';} #define FILE_NAME "data" const int MAX_N = 402; const int INF = 1e9; struct data { int cur, i, j, k, prv; data() {} data(int cur, int i, int j, int k, int prv): cur(cur), i(i), j(j), k(k), prv(prv) {} bool operator<(const data &D) const { if (cur!=D.cur) return cur<D.cur; if (i!=D.i) return i<D.i; if (j!=D.j) return j<D.j; if (k!=D.k) return k<D.k; return prv<D.prv; } }; int n, a[MAX_N]; map<data, int> f; vector<int> r, g, y; void readInput() { cin >> n; for (int i=1; i<=n; ++i) { char c; cin >> c; if (c=='R') r.push_back(i); else if (c=='G') g.push_back(i); else y.push_back(i); } } int dp(int cur, int i, int j, int k, int prv) { if (cur==n+1) return 0; if (f.count(data(cur, i, j, k, prv))) return f[data(cur, i, j, k, prv)]; int res = INF; if (i<r.size() && prv!=0) res = min(res, dp(cur+1, i+1, j, k, 0) + max(0, r[i]-cur)); if (j<g.size() && prv!=1) res = min(res, dp(cur+1, i, j+1, k, 1) + max(0, g[j]-cur)); if (k<y.size() && prv!=2) res = min(res, dp(cur+1, i, j, k+1, 2) + max(0, y[k]-cur)); return f[data(cur, i, j, k, prv)] = res; } void solve() { int tmp = dp(1, 0, 0, 0, 3); if (tmp==INF) cout << -1; else cout << tmp; } int main() { #ifdef GLASSES_GIRL freopen(FILE_NAME".in", "r", stdin); freopen(FILE_NAME".out", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); readInput(); solve(); }

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'int dp(int, int, int, int, int)':
joi2019_ho_t3.cpp:65:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (i<r.size() && prv!=0)
      ~^~~~~~~~~
joi2019_ho_t3.cpp:67:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (j<g.size() && prv!=1)
      ~^~~~~~~~~
joi2019_ho_t3.cpp:69:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (k<y.size() && prv!=2)
      ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...