Submission #19180

# Submission time Handle Problem Language Result Execution time Memory
19180 2016-02-19T14:16:57 Z tncks0121 달리는 게임 (kriii3_E) C++14
26 / 70
1000 ms 32348 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <time.h>
#include <functional>
#include <numeric>
 
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

#define debug(format, ...) printf(format, __VA_ARGS__);

const int N_ = 1000500;

int N;

ll A[N_];
ll S1[N_], S2[N_];

ll cost (int l, int r) {
    return (S2[r] - S2[l-1]) - (S1[r] - S1[l-1]) * (l-1);
}

struct line {
    ll a, b;
    line (ll a = 0, ll b = 0): a(a), b(b) { }
    ll y (ll x) { return a * x + b; }
};

struct CHT {
    vector<line> stk;

    void add (line p) {

    }
} cht;

ll tb[N_];

int main() {
    scanf("%d", &N);
    for(int i = 1; i <= N; i++) {
        scanf("%lld", A+i);
        S1[i] = S1[i-1] + A[i];
        S2[i] = S2[i-1] + i * A[i];
    }

    for(int i = 1; i <= N; i++) {
        tb[i] = tb[i-1];
        for(int j = 0; j < i; j++) {
            ll val = tb[j] + S2[i] 
                - (S1[i]) * j 
                + (-S2[j] + S1[j] * j);
            tb[i] = max(tb[i], val);
        }
    }

    printf("%lld\n", tb[N]);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 32348 KB Output is correct
2 Correct 0 ms 32348 KB Output is correct
3 Correct 0 ms 32348 KB Output is correct
4 Correct 3 ms 32348 KB Output is correct
5 Correct 0 ms 32348 KB Output is correct
6 Correct 0 ms 32348 KB Output is correct
7 Correct 2 ms 32348 KB Output is correct
8 Correct 0 ms 32348 KB Output is correct
9 Correct 2 ms 32348 KB Output is correct
10 Correct 2 ms 32348 KB Output is correct
11 Correct 0 ms 32348 KB Output is correct
12 Correct 2 ms 32348 KB Output is correct
13 Correct 0 ms 32348 KB Output is correct
14 Correct 2 ms 32348 KB Output is correct
15 Correct 0 ms 32348 KB Output is correct
16 Correct 0 ms 32348 KB Output is correct
17 Correct 2 ms 32348 KB Output is correct
18 Correct 2 ms 32348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 32344 KB Program timed out
2 Halted 0 ms 0 KB -