답안 #219762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
219762 2020-04-06T09:48:36 Z Mercenary Mountains (IOI17_mountains) C++14
100 / 100
38 ms 8448 KB
#include"mountains.h"

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 2e3 + 5;
const int mod = 1e9 + 7;

int n;
vector<int> a;
int f[maxn][maxn];
int solve(int l , int r){
    if(l == r)return 1;
    if(l > r)return 0;
    int & res = f[l][r];
    if(res > 0)return res;
    int mx = l;
    for(int i = l ; i <= r ; ++i)if(a[mx] < a[i])mx = i;
    int sum = 1;//choose mx
    auto See = [&](int i , int j , int k)->bool{
       return 1ll * (a[i] - a[j]) * (i - k) > 1ll * (a[i] - a[k]) * (i - j);
    };
    for(int i = mx + 1 ; i <= r ; ){
        int j = i + 1;
        for( ; j <= r ; ++j){
            if(See(mx,i,j)){
                if(j == r)sum += solve(i + 1,  r);
            }else{
                sum += solve(i + 1 , j - 1);
                break;
            }
        }
        i = j;
    }
    for(int i = mx - 1 ; i >= l ; ){
        int j = i - 1;
        for( ; j >= l ; --j){
            if(See(j,i,mx)){
                if(j == l)sum += solve(l ,  i - 1);
            }else{
                sum += solve(j + 1 , i - 1);
                break;
            }
        }
        i = j;
    }
    return res = max(sum , solve(l , mx - 1) + solve(mx + 1 , r));
}
int maximum_deevs(vector<int> A) {
    a = A;
    n = a.size();
    return solve(0 , n - 1);
}
//int main()
//{
//    ios_base::sync_with_stdio(0);
//    cin.tie(0);
//    if(fopen(taskname".INP","r")){
//		freopen(taskname".INP", "r",stdin);
//		freopen(taskname".OUT", "w",stdout);
//    }
//
//}

# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 4 ms 256 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 4 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 512 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 4 ms 256 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 4 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 512 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 5 ms 640 KB Output is correct
40 Correct 5 ms 768 KB Output is correct
41 Correct 5 ms 768 KB Output is correct
42 Correct 5 ms 640 KB Output is correct
43 Correct 5 ms 768 KB Output is correct
44 Correct 5 ms 768 KB Output is correct
45 Correct 6 ms 896 KB Output is correct
46 Correct 5 ms 768 KB Output is correct
47 Correct 5 ms 896 KB Output is correct
48 Correct 6 ms 864 KB Output is correct
49 Correct 5 ms 896 KB Output is correct
50 Correct 5 ms 896 KB Output is correct
51 Correct 5 ms 640 KB Output is correct
52 Correct 7 ms 1072 KB Output is correct
53 Correct 7 ms 1024 KB Output is correct
54 Correct 7 ms 1024 KB Output is correct
55 Correct 7 ms 1024 KB Output is correct
56 Correct 7 ms 1024 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 5 ms 896 KB Output is correct
59 Correct 5 ms 896 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 5 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 4 ms 256 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 4 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 512 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 5 ms 640 KB Output is correct
40 Correct 5 ms 768 KB Output is correct
41 Correct 5 ms 768 KB Output is correct
42 Correct 5 ms 640 KB Output is correct
43 Correct 5 ms 768 KB Output is correct
44 Correct 5 ms 768 KB Output is correct
45 Correct 6 ms 896 KB Output is correct
46 Correct 5 ms 768 KB Output is correct
47 Correct 5 ms 896 KB Output is correct
48 Correct 6 ms 864 KB Output is correct
49 Correct 5 ms 896 KB Output is correct
50 Correct 5 ms 896 KB Output is correct
51 Correct 5 ms 640 KB Output is correct
52 Correct 7 ms 1072 KB Output is correct
53 Correct 7 ms 1024 KB Output is correct
54 Correct 7 ms 1024 KB Output is correct
55 Correct 7 ms 1024 KB Output is correct
56 Correct 7 ms 1024 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 5 ms 896 KB Output is correct
59 Correct 5 ms 896 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 5 ms 1536 KB Output is correct
62 Correct 6 ms 1664 KB Output is correct
63 Correct 7 ms 3072 KB Output is correct
64 Correct 7 ms 3200 KB Output is correct
65 Correct 7 ms 3072 KB Output is correct
66 Correct 7 ms 3072 KB Output is correct
67 Correct 7 ms 3200 KB Output is correct
68 Correct 7 ms 3072 KB Output is correct
69 Correct 7 ms 3072 KB Output is correct
70 Correct 15 ms 4352 KB Output is correct
71 Correct 15 ms 4352 KB Output is correct
72 Correct 15 ms 4224 KB Output is correct
73 Correct 15 ms 4352 KB Output is correct
74 Correct 15 ms 4352 KB Output is correct
75 Correct 15 ms 4224 KB Output is correct
76 Correct 6 ms 2432 KB Output is correct
77 Correct 35 ms 7928 KB Output is correct
78 Correct 32 ms 7936 KB Output is correct
79 Correct 38 ms 7928 KB Output is correct
80 Correct 34 ms 7800 KB Output is correct
81 Correct 35 ms 7928 KB Output is correct
82 Correct 17 ms 512 KB Output is correct
83 Correct 21 ms 3968 KB Output is correct
84 Correct 18 ms 4096 KB Output is correct
85 Correct 16 ms 512 KB Output is correct
86 Correct 21 ms 8448 KB Output is correct