Submission #384798

# Submission time Handle Problem Language Result Execution time Memory
384798 2021-04-02T09:45:59 Z apostoldaniel854 Mountains (IOI17_mountains) C++14
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>

using namespace std;

//#define HOME


#ifndef HOME
#include "mountains.h"
#endif // HOME

using ll = long long;

struct point_t {
    int x;
    int y;
};
/**
6
6 1 5 2 3 1

**/
const int MAX_N = 2000;
point_t p[1 + MAX_N];
int dp[1 + MAX_N][1 + MAX_N];

bool ccw (point_t a, point_t b, point_t c) {
   return 1ll * (b.y - a.y) * (c.x - a.x) <= 1ll * (c.y - a.y) * (b.x - b.x);
}

int maximum_deevs(std::vector<int> y) {
    int n = y.size ();
	for (int i = 1; i <= n; i++)
        p[i] = {i, y[i - 1]};
    for (int i = 1; i <= n; i++) {
        int k = i; dp[i][i] = 1;
        int offset = 0;
        for (int j = i - 1; j > 0; j--) {
            dp[j][i] = dp[j][i - 1];
            if (ccw (p[j], p[k], p[i]))
                offset += dp[j + 1][k - 1], k = j;
            dp[j][i] = max (dp[j][i], 1 + offset + dp[j][k - 1]);
        }
    }
    return dp[1][n];
}


#ifdef HOME
int main() {
	int n;
	assert(1 == scanf("%d", &n));
	std::vector<int> y(n);
	for (int i = 0; i < n; i++) {
		assert(1 == scanf("%d", &y[i]));
	}
	int result = maximum_deevs(y);
	printf("%d\n", result);
	return 0;
}
#endif // HOME
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -