답안 #309997

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
309997 2020-10-05T09:18:03 Z ttnhuy313 Mountains (IOI17_mountains) C++14
0 / 100
1 ms 384 KB
#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];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Incorrect 1 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Incorrect 1 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Incorrect 1 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Incorrect 1 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -