답안 #989288

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
989288 2024-05-27T21:24:15 Z AdamGS Mountains (IOI17_mountains) C++17
100 / 100
75 ms 71360 KB
#include "mountains.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e3+7;
pair<int,int>ma1[LIM][LIM], ma2[LIM][LIM];
ll T[LIM];
int dp[LIM][LIM], odw[LIM][LIM], n;
ll ilo(int a, int b, int c) {
  pair<ll,ll>x={b-a, T[b]-T[a]}, y={c-a, T[c]-T[a]};
  return x.st*y.nd-x.nd*y.st;
}
int solve(int l, int r) {
  if(l>r) return 0;
  if(odw[l][r]) return dp[l][r];
  odw[l][r]=1;
  if(ma1[l][r].nd!=-ma2[l][r].nd) {
    dp[l][r]=max(solve(l, -ma2[l][r].nd-1)+solve(-ma2[l][r].nd+1, r), solve(l, ma1[l][r].nd-1)+solve(ma1[l][r].nd+1, r));
    return dp[l][r];
  }
  int x=ma1[l][r].nd;
  dp[l][r]=solve(l, x-1)+solve(x+1, r);
  int sum=1, lst=x+1;
  for(int i=x+2; i<=r; ++i) {
    if(ilo(x, lst, i)>=0) {
      sum+=solve(lst+1, i-1);
      lst=i;
    }
  }
  sum+=solve(lst+1, r);
  lst=x-1;
  for(int i=x-2; i>=l; --i) {
    if(ilo(x, lst, i)<=0) {
      sum+=solve(i+1, lst-1);
      lst=i;
    }
  }
  sum+=solve(l, lst-1);
  dp[l][r]=max(dp[l][r], sum);
  return dp[l][r];
}
int maximum_deevs(vector<int>_y) {
  n=_y.size();
  rep(i, n) T[i]=_y[i];
  rep(i, n) {
    ma1[i][i]={T[i], i};
    ma2[i][i]={T[i], -i};
    for(int j=i+1; j<n; ++j) {
      ma1[i][j]=max(ma1[i][j-1], {T[j], j});
      ma2[i][j]=max(ma2[i][j-1], {T[j], -j});
    }
  }
  return solve(0, n-1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2652 KB Output is correct
8 Correct 0 ms 2652 KB Output is correct
9 Correct 0 ms 2408 KB Output is correct
10 Correct 1 ms 4536 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 0 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2652 KB Output is correct
8 Correct 0 ms 2652 KB Output is correct
9 Correct 0 ms 2408 KB Output is correct
10 Correct 1 ms 4536 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 0 ms 2652 KB Output is correct
17 Correct 1 ms 4696 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 1 ms 2648 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 0 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 4536 KB Output is correct
33 Correct 0 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 2908 KB Output is correct
38 Correct 1 ms 4696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2652 KB Output is correct
8 Correct 0 ms 2652 KB Output is correct
9 Correct 0 ms 2408 KB Output is correct
10 Correct 1 ms 4536 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 0 ms 2652 KB Output is correct
17 Correct 1 ms 4696 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 1 ms 2648 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 0 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 4536 KB Output is correct
33 Correct 0 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 2908 KB Output is correct
38 Correct 1 ms 4696 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 2 ms 6236 KB Output is correct
41 Correct 2 ms 6236 KB Output is correct
42 Correct 2 ms 5980 KB Output is correct
43 Correct 2 ms 6236 KB Output is correct
44 Correct 2 ms 6236 KB Output is correct
45 Correct 2 ms 5980 KB Output is correct
46 Correct 2 ms 5980 KB Output is correct
47 Correct 2 ms 7772 KB Output is correct
48 Correct 2 ms 5920 KB Output is correct
49 Correct 2 ms 7772 KB Output is correct
50 Correct 2 ms 5980 KB Output is correct
51 Correct 2 ms 8024 KB Output is correct
52 Correct 3 ms 6492 KB Output is correct
53 Correct 2 ms 6492 KB Output is correct
54 Correct 2 ms 8296 KB Output is correct
55 Correct 2 ms 6748 KB Output is correct
56 Correct 3 ms 8536 KB Output is correct
57 Correct 1 ms 4956 KB Output is correct
58 Correct 2 ms 8284 KB Output is correct
59 Correct 2 ms 6748 KB Output is correct
60 Correct 1 ms 4956 KB Output is correct
61 Correct 2 ms 7512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2652 KB Output is correct
8 Correct 0 ms 2652 KB Output is correct
9 Correct 0 ms 2408 KB Output is correct
10 Correct 1 ms 4536 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 0 ms 2652 KB Output is correct
17 Correct 1 ms 4696 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 1 ms 2648 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 0 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 4536 KB Output is correct
33 Correct 0 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 2908 KB Output is correct
38 Correct 1 ms 4696 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 2 ms 6236 KB Output is correct
41 Correct 2 ms 6236 KB Output is correct
42 Correct 2 ms 5980 KB Output is correct
43 Correct 2 ms 6236 KB Output is correct
44 Correct 2 ms 6236 KB Output is correct
45 Correct 2 ms 5980 KB Output is correct
46 Correct 2 ms 5980 KB Output is correct
47 Correct 2 ms 7772 KB Output is correct
48 Correct 2 ms 5920 KB Output is correct
49 Correct 2 ms 7772 KB Output is correct
50 Correct 2 ms 5980 KB Output is correct
51 Correct 2 ms 8024 KB Output is correct
52 Correct 3 ms 6492 KB Output is correct
53 Correct 2 ms 6492 KB Output is correct
54 Correct 2 ms 8296 KB Output is correct
55 Correct 2 ms 6748 KB Output is correct
56 Correct 3 ms 8536 KB Output is correct
57 Correct 1 ms 4956 KB Output is correct
58 Correct 2 ms 8284 KB Output is correct
59 Correct 2 ms 6748 KB Output is correct
60 Correct 1 ms 4956 KB Output is correct
61 Correct 2 ms 7512 KB Output is correct
62 Correct 8 ms 21084 KB Output is correct
63 Correct 24 ms 54352 KB Output is correct
64 Correct 22 ms 54364 KB Output is correct
65 Correct 22 ms 55252 KB Output is correct
66 Correct 23 ms 55332 KB Output is correct
67 Correct 32 ms 55400 KB Output is correct
68 Correct 26 ms 55132 KB Output is correct
69 Correct 22 ms 55132 KB Output is correct
70 Correct 26 ms 55124 KB Output is correct
71 Correct 24 ms 55132 KB Output is correct
72 Correct 24 ms 55132 KB Output is correct
73 Correct 25 ms 55124 KB Output is correct
74 Correct 24 ms 55128 KB Output is correct
75 Correct 24 ms 55128 KB Output is correct
76 Correct 23 ms 55384 KB Output is correct
77 Correct 75 ms 71248 KB Output is correct
78 Correct 74 ms 71196 KB Output is correct
79 Correct 73 ms 71360 KB Output is correct
80 Correct 73 ms 71248 KB Output is correct
81 Correct 70 ms 71248 KB Output is correct
82 Correct 23 ms 47452 KB Output is correct
83 Correct 27 ms 57936 KB Output is correct
84 Correct 32 ms 58196 KB Output is correct
85 Correct 22 ms 47444 KB Output is correct
86 Correct 27 ms 63324 KB Output is correct