Submission #319999

# Submission time Handle Problem Language Result Execution time Memory
319999 2020-11-07T06:32:29 Z LifeHappen__ Mountains (IOI17_mountains) C++14
100 / 100
54 ms 16364 KB
#ifndef LOCAL
#include "mountains.h"
#endif // LOCAL

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define forinc(a,b,c) for(int a=b, _c=c; a<=_c; ++a)
#define fordec(a,b,c) for(int a=b, _c=c; a>=_c; --a)
#define forv(a,b) for(auto &a:b)
#define fasty ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ii pair<int,int>
#define fi first
#define se second
#define ar array
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define reset(f,x) memset(f,x,sizeof(f))
#define bit(x,i) (x>>(i-1)&1ll)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1ll<<(i-1)))

const int N=2005;
int n;
int dp[N][N];

int maximum_deevs(vector<int> y){
   auto ccw=[&](int i,int j,int k){
      return (long long)(y[i]-y[j])*(i-k)>(long long)(y[i]-y[k])*(i-j);
   };
   function<int(int,int)> solve=[&](int l,int r){
      if(l>r) return 0;
      if(l==r) return 1;
      if(dp[l][r]!=-1) return dp[l][r];
      int maxi=l;
      forinc(i,l,r) if(y[maxi]<y[i]) maxi=i;
      int tot=1;
      for(int i=maxi+1; i<=r; ){
         int j=i+1;
         for(; j<=r; ++j){
            if(ccw(maxi,i,j)) {if(j==r) tot+=solve(i+1,r);}
            else{
               tot+=solve(i+1,j-1);
               break;
            }
         }
         i=j;
      }
      for(int i=maxi-1; i>=l; ){
         int j=i-1;
         for(; j>=l; --j){
            if(ccw(j,i,maxi)){
               if(j==l) tot+=solve(l,i-1);
            } else{
               tot+=solve(j+1,i-1);
               break;
            }
         }
         i=j;
      }
      return dp[l][r]=max(tot, solve(l,maxi-1)+solve(maxi+1,r));
   };
   reset(dp,-1);
   return solve(0,y.size()-1);
}

#ifdef LOCAL
int32_t main(){
   fasty;

   cin>>n;
   vector<int> y(n);
   forv(v,y) cin>>v;
   cout<<maximum_deevs(y)<<'\n';
}
#endif //LOCAL
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16108 KB Output is correct
2 Correct 8 ms 16128 KB Output is correct
3 Correct 8 ms 16108 KB Output is correct
4 Correct 9 ms 16108 KB Output is correct
5 Correct 8 ms 16108 KB Output is correct
6 Correct 8 ms 16108 KB Output is correct
7 Correct 9 ms 16000 KB Output is correct
8 Correct 10 ms 16256 KB Output is correct
9 Correct 10 ms 16108 KB Output is correct
10 Correct 8 ms 16108 KB Output is correct
11 Correct 9 ms 16108 KB Output is correct
12 Correct 8 ms 16108 KB Output is correct
13 Correct 9 ms 16108 KB Output is correct
14 Correct 8 ms 16108 KB Output is correct
15 Correct 8 ms 16108 KB Output is correct
16 Correct 8 ms 16108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16108 KB Output is correct
2 Correct 8 ms 16128 KB Output is correct
3 Correct 8 ms 16108 KB Output is correct
4 Correct 9 ms 16108 KB Output is correct
5 Correct 8 ms 16108 KB Output is correct
6 Correct 8 ms 16108 KB Output is correct
7 Correct 9 ms 16000 KB Output is correct
8 Correct 10 ms 16256 KB Output is correct
9 Correct 10 ms 16108 KB Output is correct
10 Correct 8 ms 16108 KB Output is correct
11 Correct 9 ms 16108 KB Output is correct
12 Correct 8 ms 16108 KB Output is correct
13 Correct 9 ms 16108 KB Output is correct
14 Correct 8 ms 16108 KB Output is correct
15 Correct 8 ms 16108 KB Output is correct
16 Correct 8 ms 16108 KB Output is correct
17 Correct 8 ms 16236 KB Output is correct
18 Correct 10 ms 16108 KB Output is correct
19 Correct 9 ms 16108 KB Output is correct
20 Correct 9 ms 16108 KB Output is correct
21 Correct 10 ms 16256 KB Output is correct
22 Correct 8 ms 16128 KB Output is correct
23 Correct 9 ms 16108 KB Output is correct
24 Correct 9 ms 16108 KB Output is correct
25 Correct 9 ms 16108 KB Output is correct
26 Correct 8 ms 16108 KB Output is correct
27 Correct 9 ms 16256 KB Output is correct
28 Correct 9 ms 16248 KB Output is correct
29 Correct 8 ms 16108 KB Output is correct
30 Correct 9 ms 16012 KB Output is correct
31 Correct 10 ms 16108 KB Output is correct
32 Correct 8 ms 16108 KB Output is correct
33 Correct 8 ms 16108 KB Output is correct
34 Correct 8 ms 16108 KB Output is correct
35 Correct 8 ms 16108 KB Output is correct
36 Correct 9 ms 16108 KB Output is correct
37 Correct 8 ms 16108 KB Output is correct
38 Correct 8 ms 16108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16108 KB Output is correct
2 Correct 8 ms 16128 KB Output is correct
3 Correct 8 ms 16108 KB Output is correct
4 Correct 9 ms 16108 KB Output is correct
5 Correct 8 ms 16108 KB Output is correct
6 Correct 8 ms 16108 KB Output is correct
7 Correct 9 ms 16000 KB Output is correct
8 Correct 10 ms 16256 KB Output is correct
9 Correct 10 ms 16108 KB Output is correct
10 Correct 8 ms 16108 KB Output is correct
11 Correct 9 ms 16108 KB Output is correct
12 Correct 8 ms 16108 KB Output is correct
13 Correct 9 ms 16108 KB Output is correct
14 Correct 8 ms 16108 KB Output is correct
15 Correct 8 ms 16108 KB Output is correct
16 Correct 8 ms 16108 KB Output is correct
17 Correct 8 ms 16236 KB Output is correct
18 Correct 10 ms 16108 KB Output is correct
19 Correct 9 ms 16108 KB Output is correct
20 Correct 9 ms 16108 KB Output is correct
21 Correct 10 ms 16256 KB Output is correct
22 Correct 8 ms 16128 KB Output is correct
23 Correct 9 ms 16108 KB Output is correct
24 Correct 9 ms 16108 KB Output is correct
25 Correct 9 ms 16108 KB Output is correct
26 Correct 8 ms 16108 KB Output is correct
27 Correct 9 ms 16256 KB Output is correct
28 Correct 9 ms 16248 KB Output is correct
29 Correct 8 ms 16108 KB Output is correct
30 Correct 9 ms 16012 KB Output is correct
31 Correct 10 ms 16108 KB Output is correct
32 Correct 8 ms 16108 KB Output is correct
33 Correct 8 ms 16108 KB Output is correct
34 Correct 8 ms 16108 KB Output is correct
35 Correct 8 ms 16108 KB Output is correct
36 Correct 9 ms 16108 KB Output is correct
37 Correct 8 ms 16108 KB Output is correct
38 Correct 8 ms 16108 KB Output is correct
39 Correct 8 ms 16108 KB Output is correct
40 Correct 9 ms 16108 KB Output is correct
41 Correct 9 ms 16108 KB Output is correct
42 Correct 9 ms 16236 KB Output is correct
43 Correct 9 ms 16108 KB Output is correct
44 Correct 8 ms 16108 KB Output is correct
45 Correct 9 ms 16236 KB Output is correct
46 Correct 9 ms 16108 KB Output is correct
47 Correct 9 ms 16236 KB Output is correct
48 Correct 9 ms 16236 KB Output is correct
49 Correct 9 ms 16108 KB Output is correct
50 Correct 9 ms 16236 KB Output is correct
51 Correct 9 ms 16108 KB Output is correct
52 Correct 11 ms 16108 KB Output is correct
53 Correct 11 ms 16140 KB Output is correct
54 Correct 11 ms 16108 KB Output is correct
55 Correct 11 ms 16108 KB Output is correct
56 Correct 12 ms 16108 KB Output is correct
57 Correct 9 ms 16108 KB Output is correct
58 Correct 9 ms 16108 KB Output is correct
59 Correct 9 ms 16108 KB Output is correct
60 Correct 9 ms 16236 KB Output is correct
61 Correct 9 ms 16108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16108 KB Output is correct
2 Correct 8 ms 16128 KB Output is correct
3 Correct 8 ms 16108 KB Output is correct
4 Correct 9 ms 16108 KB Output is correct
5 Correct 8 ms 16108 KB Output is correct
6 Correct 8 ms 16108 KB Output is correct
7 Correct 9 ms 16000 KB Output is correct
8 Correct 10 ms 16256 KB Output is correct
9 Correct 10 ms 16108 KB Output is correct
10 Correct 8 ms 16108 KB Output is correct
11 Correct 9 ms 16108 KB Output is correct
12 Correct 8 ms 16108 KB Output is correct
13 Correct 9 ms 16108 KB Output is correct
14 Correct 8 ms 16108 KB Output is correct
15 Correct 8 ms 16108 KB Output is correct
16 Correct 8 ms 16108 KB Output is correct
17 Correct 8 ms 16236 KB Output is correct
18 Correct 10 ms 16108 KB Output is correct
19 Correct 9 ms 16108 KB Output is correct
20 Correct 9 ms 16108 KB Output is correct
21 Correct 10 ms 16256 KB Output is correct
22 Correct 8 ms 16128 KB Output is correct
23 Correct 9 ms 16108 KB Output is correct
24 Correct 9 ms 16108 KB Output is correct
25 Correct 9 ms 16108 KB Output is correct
26 Correct 8 ms 16108 KB Output is correct
27 Correct 9 ms 16256 KB Output is correct
28 Correct 9 ms 16248 KB Output is correct
29 Correct 8 ms 16108 KB Output is correct
30 Correct 9 ms 16012 KB Output is correct
31 Correct 10 ms 16108 KB Output is correct
32 Correct 8 ms 16108 KB Output is correct
33 Correct 8 ms 16108 KB Output is correct
34 Correct 8 ms 16108 KB Output is correct
35 Correct 8 ms 16108 KB Output is correct
36 Correct 9 ms 16108 KB Output is correct
37 Correct 8 ms 16108 KB Output is correct
38 Correct 8 ms 16108 KB Output is correct
39 Correct 8 ms 16108 KB Output is correct
40 Correct 9 ms 16108 KB Output is correct
41 Correct 9 ms 16108 KB Output is correct
42 Correct 9 ms 16236 KB Output is correct
43 Correct 9 ms 16108 KB Output is correct
44 Correct 8 ms 16108 KB Output is correct
45 Correct 9 ms 16236 KB Output is correct
46 Correct 9 ms 16108 KB Output is correct
47 Correct 9 ms 16236 KB Output is correct
48 Correct 9 ms 16236 KB Output is correct
49 Correct 9 ms 16108 KB Output is correct
50 Correct 9 ms 16236 KB Output is correct
51 Correct 9 ms 16108 KB Output is correct
52 Correct 11 ms 16108 KB Output is correct
53 Correct 11 ms 16140 KB Output is correct
54 Correct 11 ms 16108 KB Output is correct
55 Correct 11 ms 16108 KB Output is correct
56 Correct 12 ms 16108 KB Output is correct
57 Correct 9 ms 16108 KB Output is correct
58 Correct 9 ms 16108 KB Output is correct
59 Correct 9 ms 16108 KB Output is correct
60 Correct 9 ms 16236 KB Output is correct
61 Correct 9 ms 16108 KB Output is correct
62 Correct 9 ms 16108 KB Output is correct
63 Correct 9 ms 16108 KB Output is correct
64 Correct 9 ms 16108 KB Output is correct
65 Correct 9 ms 16108 KB Output is correct
66 Correct 9 ms 16252 KB Output is correct
67 Correct 10 ms 16236 KB Output is correct
68 Correct 9 ms 16108 KB Output is correct
69 Correct 10 ms 16236 KB Output is correct
70 Correct 19 ms 16236 KB Output is correct
71 Correct 19 ms 16236 KB Output is correct
72 Correct 20 ms 16236 KB Output is correct
73 Correct 20 ms 16236 KB Output is correct
74 Correct 21 ms 16236 KB Output is correct
75 Correct 20 ms 16236 KB Output is correct
76 Correct 9 ms 16108 KB Output is correct
77 Correct 51 ms 16236 KB Output is correct
78 Correct 45 ms 16228 KB Output is correct
79 Correct 54 ms 16228 KB Output is correct
80 Correct 47 ms 16364 KB Output is correct
81 Correct 47 ms 16228 KB Output is correct
82 Correct 20 ms 16236 KB Output is correct
83 Correct 24 ms 16108 KB Output is correct
84 Correct 20 ms 16236 KB Output is correct
85 Correct 20 ms 16364 KB Output is correct
86 Correct 19 ms 16236 KB Output is correct