Submission #97625

#TimeUsernameProblemLanguageResultExecution timeMemory
97625polyfishGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
75 / 100
977 ms119320 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, f[MAX_N][MAX_N][MAX_N][5]; bool calculated[MAX_N][MAX_N][MAX_N][5]; vector<int> a[3]; void readInput() { cin >> n; for (int i=1; i<=n; ++i) { char c; cin >> c; if (c=='R') a[0].push_back(i); else if (c=='G') a[1].push_back(i); else a[2].push_back(i); } } int bisect(int idx, int curPos, int bound) { int l = 0, r = bound; for (int mid=(l+r)/2; mid!=l && r!=mid; mid=(l+r)/2) { if (a[idx][mid]>curPos) r = mid; else l = mid; } for (int i=l; i<=r; ++i) { if (a[idx][i]>curPos) return bound - i + 1; } return 0; } int cost(int idx, int curPos, int newPos, int i, int j, int k) { int realPos = curPos; if (idx==0) realPos += bisect(1, curPos, j-1) + bisect(2, curPos, k-1); else if (idx==1) realPos += bisect(0, curPos, i-1) + bisect(2, curPos, k-1); else realPos += bisect(0, curPos, i-1) + bisect(1, curPos, j-1); return realPos - newPos; } int dp(int cur, int i, int j, int k, int prv) { if (k>i+j+1 || i>j+k+1 || j>i+k+1) return INF; if (cur==n+1) return 0; if (calculated[i][j][k][prv]) return f[i][j][k][prv]; calculated[i][j][k][prv] = true; int res = INF; if (i<a[0].size() && prv!=0) { res = min(res, dp(cur+1, i+1, j, k, 0) + cost(0, a[0][i], cur, i, j, k)); } if (j<a[1].size() && prv!=1) { res = min(res, dp(cur+1, i, j+1, k, 1) + cost(1, a[1][j], cur, i, j, k)); } if (k<a[2].size() && prv!=2) { res = min(res, dp(cur+1, i, j, k+1, 2) + cost(2, a[2][k], cur, i, j, k)); } return f[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 cost(int, int, int, int, int, int)':
joi2019_ho_t3.cpp:60:5: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
     else
     ^~~~
joi2019_ho_t3.cpp:63:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
  return realPos - newPos;
  ^~~~~~
joi2019_ho_t3.cpp: In function 'int dp(int, int, int, int, int)':
joi2019_ho_t3.cpp:67:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if (k>i+j+1 || i>j+k+1 || j>i+k+1)
     ^~
joi2019_ho_t3.cpp:70:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  if (cur==n+1)
  ^~
joi2019_ho_t3.cpp:79:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (i<a[0].size() && prv!=0) {
      ~^~~~~~~~~~~~
joi2019_ho_t3.cpp:83:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (j<a[1].size() && prv!=1) {
      ~^~~~~~~~~~~~
joi2019_ho_t3.cpp:87:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (k<a[2].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...