Submission #240165

# Submission time Handle Problem Language Result Execution time Memory
240165 2020-06-18T10:31:47 Z lyc Mountains (IOI17_mountains) C++14
0 / 100
14 ms 16128 KB
#include "mountains.h"
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cout << #x << " :: " << x << endl;
#define _ << " " <<
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

const int mxN = 2e3+5;
int memo[mxN][mxN];

int solve(int l, int r, vector<int>& y) {
    if (l > r) return 0;
    if (l == r) return 1;
    if (~memo[l][r]) return memo[l][r];
    int mx = l;
    FOR(i,l+1,r) if (y[i] > y[mx]) mx = i;
    memo[l][r] = solve(l,mx-1,y) + solve(mx+1,r,y);
    int cur = 0, j = mx-1;
    double mng = 0;
    RFOR(i,mx-1,l){
        double g = (double)(y[mx]-y[i])/(mx-i);
        if (g < mng) mng = g;
        else {
            cur += solve(i+1,j,y);
            j = i-1;
        }
    }
    j = mx+1, mng = 0;
    FOR(i,mx+1,r){
        double g = (double)(y[mx]-y[i])/(i-mx);
        if (g < mng) mng = g;
        else {
            cur += solve(j,i-1,y);
            j = i+1;
        }
    }
    memo[l][r] = max(memo[l][r],cur);
    return memo[l][r];
}

int maximum_deevs(vector<int> y) {
    memset(memo,-1,sizeof memo);
	return solve(0,SZ(y)-1,y);
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16000 KB Output is correct
2 Correct 14 ms 16000 KB Output is correct
3 Correct 12 ms 16128 KB Output is correct
4 Correct 14 ms 16000 KB Output is correct
5 Correct 14 ms 16128 KB Output is correct
6 Incorrect 12 ms 16128 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16000 KB Output is correct
2 Correct 14 ms 16000 KB Output is correct
3 Correct 12 ms 16128 KB Output is correct
4 Correct 14 ms 16000 KB Output is correct
5 Correct 14 ms 16128 KB Output is correct
6 Incorrect 12 ms 16128 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16000 KB Output is correct
2 Correct 14 ms 16000 KB Output is correct
3 Correct 12 ms 16128 KB Output is correct
4 Correct 14 ms 16000 KB Output is correct
5 Correct 14 ms 16128 KB Output is correct
6 Incorrect 12 ms 16128 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16000 KB Output is correct
2 Correct 14 ms 16000 KB Output is correct
3 Correct 12 ms 16128 KB Output is correct
4 Correct 14 ms 16000 KB Output is correct
5 Correct 14 ms 16128 KB Output is correct
6 Incorrect 12 ms 16128 KB Output isn't correct
7 Halted 0 ms 0 KB -