답안 #384788

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384788 2021-04-02T09:36:36 Z apostoldaniel854 Mountains (IOI17_mountains) C++14
컴파일 오류
0 ms 0 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];

ll area (point_t a, point_t b, point_t c) {
    return 1ll * a.x * a.y + 1ll * b.x * c.y + 1ll * c.x * a.y - 1ll * a.y * c.x - 1ll * b.y * a.x - 1ll * c.y * 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 + 1][i];
            if (area (p[j], p[k], p[i]) >= 0)
                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
#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];

ll area (point_t a, point_t b, point_t c) {
    return 1ll * a.x * a.y + 1ll * b.x * c.y + 1ll * c.x * a.y - 1ll * a.y * c.x - 1ll * b.y * a.x - 1ll * c.y * 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 + 1][i];
            if (area (p[j], p[k], p[i]) >= 0)
                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

Compilation message

mountains.cpp:75:8: error: redefinition of 'struct point_t'
   75 | struct point_t {
      |        ^~~~~~~
mountains.cpp:14:8: note: previous definition of 'struct point_t'
   14 | struct point_t {
      |        ^~~~~~~
mountains.cpp:84:11: error: redefinition of 'const int MAX_N'
   84 | const int MAX_N = 2000;
      |           ^~~~~
mountains.cpp:23:11: note: 'const int MAX_N' previously defined here
   23 | const int MAX_N = 2000;
      |           ^~~~~
mountains.cpp:85:9: error: redefinition of 'point_t p [2001]'
   85 | point_t p[1 + MAX_N];
      |         ^
mountains.cpp:24:9: note: 'point_t p [2001]' previously declared here
   24 | point_t p[1 + MAX_N];
      |         ^
mountains.cpp:86:5: error: redefinition of 'int dp [2001][2001]'
   86 | int dp[1 + MAX_N][1 + MAX_N];
      |     ^~
mountains.cpp:25:5: note: 'int dp [2001][2001]' previously declared here
   25 | int dp[1 + MAX_N][1 + MAX_N];
      |     ^~
mountains.cpp:88:4: error: redefinition of 'll area(point_t, point_t, point_t)'
   88 | ll area (point_t a, point_t b, point_t c) {
      |    ^~~~
mountains.cpp:27:4: note: 'll area(point_t, point_t, point_t)' previously defined here
   27 | ll area (point_t a, point_t b, point_t c) {
      |    ^~~~
mountains.cpp:92:5: error: redefinition of 'int maximum_deevs(std::vector<int>)'
   92 | int maximum_deevs(std::vector<int> y) {
      |     ^~~~~~~~~~~~~
mountains.cpp:31:5: note: 'int maximum_deevs(std::vector<int>)' previously defined here
   31 | int maximum_deevs(std::vector<int> y) {
      |     ^~~~~~~~~~~~~
mountains.cpp:111:5: error: redefinition of 'int main()'
  111 | int main() {
      |     ^~~~
mountains.cpp:50:5: note: 'int main()' previously defined here
   50 | int main() {
      |     ^~~~