Submission #309997

#TimeUsernameProblemLanguageResultExecution timeMemory
309997ttnhuy313Mountains (IOI17_mountains)C++14
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define sqr(a) (a * a) typedef pair <int, int> ii; const int N = 2005; int dp[N][N]; int cross(ii a, ii b) { return a.first * b.second - a.second * b.first; } bool ccw(ii a, ii b, ii c) { return cross(ii(b.first - a.first, b.second - a.second), ii(c.first - a.first, c.second - a.second)) > 0; } int maximum_deevs(vector <int32_t> y) { int n = y.size(); for (int r = 0; r < n; ++r) { dp[r][r] = 1; if (r == 0) continue; dp[r - 1][r] = 1; int xx = 1, yy = y[r] - y[r - 1], sum = 0, lastSeen = r - 1, id = r - 1; for (int l = r - 2; l >= 0; --l) { int curx = r - l, cury = y[r] - y[l]; if (sqr(curx) * (sqr(xx) + sqr(yy)) < sqr(xx) * (sqr(curx) + sqr(cury))) { xx = curx; yy = cury; id = l; } if (ccw(ii(r, y[r]), ii(id, y[id]), ii(l, y[l]))) { // cross the mountain dp[l][r] = sum + dp[l][lastSeen - 1] + 1; } else { sum += dp[l + 1][lastSeen - 1]; lastSeen = l; } dp[l][r] = max(dp[l][r], dp[l][r - 1]); } } return dp[0][n - 1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...