Submission #97443

#TimeUsernameProblemLanguageResultExecution timeMemory
97443polyfishGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
0 / 100
857 ms1017504 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; int n, a[MAX_N], f[MAX_N][MAX_N][MAX_N][4]; 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[i][j][k][prv]>-1) return f[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[i][j][k][prv] = res; } void solve() { memset(f, -1, sizeof(f)); 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:43:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (i<r.size() && prv!=0)
      ~^~~~~~~~~
joi2019_ho_t3.cpp:45:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (j<g.size() && prv!=1)
      ~^~~~~~~~~
joi2019_ho_t3.cpp:47: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...