Submission #74425

# Submission time Handle Problem Language Result Execution time Memory
74425 2018-09-01T09:01:31 Z mjt Mountains (IOI17_mountains) C++11
0 / 100
2 ms 576 KB
#include"mountains.h"
#include<bits/stdc++.h>
using namespace std;

const int N = 2010;
int y[N];
int f[N][N];

bool pd(int a,int b,int c) {
	// ((y[a] - y[b]) / (a - b)) > ((y[a] - y[c]) / (a - c));
	return 1ll * (y[a] - y[b]) * (a - c) > 1ll * (y[a] - y[c]) * (a - b);
}
int solve(int l,int r) {
	if (f[l][r]) return f[l][r];
	if (l > r) return 0;
	if (l == r) return 1;
	int pos = -1, mx = -1;
	for (int i=l; i<=r; ++i) 
		if (y[i] > mx) pos = i, mx = y[i];
	int ans1 = solve(l, pos - 1) + solve(pos + 1, r);
	int ans2 = 0, L = pos - 1;
	for (int i=pos-2; i>=1; --i) {
		if (pd(i, L, pos)) continue;
		ans2 += solve(i + 1, L - 1);
		L = i;
	}
	return f[l][r] = max(ans1, ans2);
}

int maximum_deevs(vector<int> A) {
	int n = A.size();
	for (int i=1; i<=n; ++i) y[i] = A[i - 1];
	return solve(1, n);	
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 400 KB Output is correct
4 Correct 2 ms 576 KB Output is correct
5 Correct 2 ms 576 KB Output is correct
6 Incorrect 2 ms 576 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 400 KB Output is correct
4 Correct 2 ms 576 KB Output is correct
5 Correct 2 ms 576 KB Output is correct
6 Incorrect 2 ms 576 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 400 KB Output is correct
4 Correct 2 ms 576 KB Output is correct
5 Correct 2 ms 576 KB Output is correct
6 Incorrect 2 ms 576 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 400 KB Output is correct
4 Correct 2 ms 576 KB Output is correct
5 Correct 2 ms 576 KB Output is correct
6 Incorrect 2 ms 576 KB Output isn't correct
7 Halted 0 ms 0 KB -