Submission #320479

# Submission time Handle Problem Language Result Execution time Memory
320479 2020-11-08T20:28:04 Z egas Discharging (NOI20_discharging) C++14
36 / 100
256 ms 134736 KB
#include <bits/stdc++.h>

using namespace std;

template < typename T >

class SegmentTree {

private:

    T *Stree;

    T *Snum;

    long long n;

    T NullValue = 0;

    T combine(T a, T b) {

        return max(a,b);

    }

    void build(long long idx, long long s, long long e) {

        if (s > e)

            return;

        if (s == e) {

            Stree[idx] = Snum[s];

            return ;

        }

        long long m = ( s + e ) / 2;

        build( 2 * idx, s, m);

        build( 2 * idx + 1, m + 1, e);

        Stree[idx] = combine(Stree[2 * idx], Stree[2 * idx + 1] );

        return;

    }

    T queryUtil(long long idx, long long s, long long e, long long l, long long r) {

        if (l > e || r < s)

            return NullValue;

        if (s >= l && e <= r) {

            return Stree[idx];

        }

        long long m = ( s + e ) / 2;

        T left = queryUtil(2 * idx, s, m, l, r);

        T right = queryUtil(2 * idx + 1, m + 1, e, l, r);

        return combine(left, right );

    }

public:

    SegmentTree(vector<T> a) {

        this->n = a.size();

        Stree = new T[4 * n + 5];

        Snum = new T[n];

        for (long long i = 0; i < n; i++) {

            Snum[i] = a[i];

        }

        build(1, 0, n - 1);

    }

    T query(long long l, long long r) {

        return queryUtil(1, 0, n - 1, l - 1, r - 1);

    }

};

long long dp[2000][2000];

long long solve(long long idx,long long last,long long n,SegmentTree<long long> &ST) {

    if(idx>=n)return 0;

    if(dp[idx][last]!=-1) {

        return dp[idx][last];

    }

    if(last>=n) {

        dp[idx][last]=ST.query(idx+1,last+1)*(n-idx);

        return ST.query(idx+1,last+1)*(n-idx);

    }

    long long pos1 = ST.query(idx+1,last+1)*(n-idx) + solve(last+1,last+1,n,ST);

    long long pos2 = solve(idx,last+1,n,ST);

    dp[idx][last]=min(pos1,pos2);

    return min(pos1,pos2);

}

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    long long n;

    cin >> n;

    vector<long long> a(n);
    
	memset(dp,-1,sizeof dp);
    
    for(long long i = 0 ; i < n ; i++) {

        cin >> a[i];

    }

    SegmentTree<long long> ST(a);

    long long res = solve(0,0,n,ST);

    cout << res << '\n';

    return 0;

}

# Verdict Execution time Memory Grader output
1 Correct 16 ms 31596 KB Output is correct
2 Correct 16 ms 31596 KB Output is correct
3 Correct 17 ms 31596 KB Output is correct
4 Correct 16 ms 31596 KB Output is correct
5 Correct 16 ms 31596 KB Output is correct
6 Correct 15 ms 31596 KB Output is correct
7 Correct 16 ms 31596 KB Output is correct
8 Correct 16 ms 31596 KB Output is correct
9 Correct 16 ms 31596 KB Output is correct
10 Correct 17 ms 31596 KB Output is correct
11 Correct 16 ms 31596 KB Output is correct
12 Correct 16 ms 31596 KB Output is correct
13 Correct 16 ms 31596 KB Output is correct
14 Correct 16 ms 31596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 158 ms 31980 KB Output is correct
2 Correct 146 ms 32100 KB Output is correct
3 Correct 177 ms 31980 KB Output is correct
4 Correct 144 ms 32100 KB Output is correct
5 Correct 161 ms 32096 KB Output is correct
6 Correct 153 ms 32012 KB Output is correct
7 Correct 155 ms 31980 KB Output is correct
8 Correct 142 ms 32100 KB Output is correct
9 Correct 160 ms 32128 KB Output is correct
10 Correct 141 ms 31980 KB Output is correct
11 Correct 163 ms 32100 KB Output is correct
12 Correct 193 ms 31980 KB Output is correct
13 Correct 146 ms 31992 KB Output is correct
14 Correct 164 ms 32100 KB Output is correct
15 Correct 147 ms 31980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 158 ms 31980 KB Output is correct
2 Correct 146 ms 32100 KB Output is correct
3 Correct 177 ms 31980 KB Output is correct
4 Correct 144 ms 32100 KB Output is correct
5 Correct 161 ms 32096 KB Output is correct
6 Correct 153 ms 32012 KB Output is correct
7 Correct 155 ms 31980 KB Output is correct
8 Correct 142 ms 32100 KB Output is correct
9 Correct 160 ms 32128 KB Output is correct
10 Correct 141 ms 31980 KB Output is correct
11 Correct 163 ms 32100 KB Output is correct
12 Correct 193 ms 31980 KB Output is correct
13 Correct 146 ms 31992 KB Output is correct
14 Correct 164 ms 32100 KB Output is correct
15 Correct 147 ms 31980 KB Output is correct
16 Runtime error 231 ms 134736 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 256 ms 129616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31596 KB Output is correct
2 Correct 16 ms 31596 KB Output is correct
3 Correct 17 ms 31596 KB Output is correct
4 Correct 16 ms 31596 KB Output is correct
5 Correct 16 ms 31596 KB Output is correct
6 Correct 15 ms 31596 KB Output is correct
7 Correct 16 ms 31596 KB Output is correct
8 Correct 16 ms 31596 KB Output is correct
9 Correct 16 ms 31596 KB Output is correct
10 Correct 17 ms 31596 KB Output is correct
11 Correct 16 ms 31596 KB Output is correct
12 Correct 16 ms 31596 KB Output is correct
13 Correct 16 ms 31596 KB Output is correct
14 Correct 16 ms 31596 KB Output is correct
15 Correct 158 ms 31980 KB Output is correct
16 Correct 146 ms 32100 KB Output is correct
17 Correct 177 ms 31980 KB Output is correct
18 Correct 144 ms 32100 KB Output is correct
19 Correct 161 ms 32096 KB Output is correct
20 Correct 153 ms 32012 KB Output is correct
21 Correct 155 ms 31980 KB Output is correct
22 Correct 142 ms 32100 KB Output is correct
23 Correct 160 ms 32128 KB Output is correct
24 Correct 141 ms 31980 KB Output is correct
25 Correct 163 ms 32100 KB Output is correct
26 Correct 193 ms 31980 KB Output is correct
27 Correct 146 ms 31992 KB Output is correct
28 Correct 164 ms 32100 KB Output is correct
29 Correct 147 ms 31980 KB Output is correct
30 Correct 171 ms 31980 KB Output is correct
31 Correct 163 ms 31980 KB Output is correct
32 Correct 145 ms 32100 KB Output is correct
33 Correct 153 ms 31980 KB Output is correct
34 Correct 144 ms 31980 KB Output is correct
35 Correct 203 ms 31980 KB Output is correct
36 Correct 159 ms 32100 KB Output is correct
37 Correct 155 ms 31980 KB Output is correct
38 Correct 173 ms 32012 KB Output is correct
39 Correct 161 ms 32140 KB Output is correct
40 Correct 142 ms 31980 KB Output is correct
41 Correct 173 ms 31980 KB Output is correct
42 Correct 191 ms 31980 KB Output is correct
43 Correct 163 ms 31980 KB Output is correct
44 Correct 150 ms 32000 KB Output is correct
45 Correct 151 ms 31980 KB Output is correct
46 Correct 151 ms 32100 KB Output is correct
47 Correct 166 ms 32100 KB Output is correct
48 Correct 144 ms 32100 KB Output is correct
49 Correct 147 ms 31980 KB Output is correct
50 Correct 164 ms 31980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31596 KB Output is correct
2 Correct 16 ms 31596 KB Output is correct
3 Correct 17 ms 31596 KB Output is correct
4 Correct 16 ms 31596 KB Output is correct
5 Correct 16 ms 31596 KB Output is correct
6 Correct 15 ms 31596 KB Output is correct
7 Correct 16 ms 31596 KB Output is correct
8 Correct 16 ms 31596 KB Output is correct
9 Correct 16 ms 31596 KB Output is correct
10 Correct 17 ms 31596 KB Output is correct
11 Correct 16 ms 31596 KB Output is correct
12 Correct 16 ms 31596 KB Output is correct
13 Correct 16 ms 31596 KB Output is correct
14 Correct 16 ms 31596 KB Output is correct
15 Correct 158 ms 31980 KB Output is correct
16 Correct 146 ms 32100 KB Output is correct
17 Correct 177 ms 31980 KB Output is correct
18 Correct 144 ms 32100 KB Output is correct
19 Correct 161 ms 32096 KB Output is correct
20 Correct 153 ms 32012 KB Output is correct
21 Correct 155 ms 31980 KB Output is correct
22 Correct 142 ms 32100 KB Output is correct
23 Correct 160 ms 32128 KB Output is correct
24 Correct 141 ms 31980 KB Output is correct
25 Correct 163 ms 32100 KB Output is correct
26 Correct 193 ms 31980 KB Output is correct
27 Correct 146 ms 31992 KB Output is correct
28 Correct 164 ms 32100 KB Output is correct
29 Correct 147 ms 31980 KB Output is correct
30 Runtime error 231 ms 134736 KB Execution killed with signal 11 (could be triggered by violating memory limits)
31 Halted 0 ms 0 KB -