# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
285466 | arnold518 | Discharging (NOI20_discharging) | C++14 | 1056 ms | 17856 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e6;
const ll INF = 1e15;
int N;
ll dp[MAXN+10], A[MAXN+10];
int main()
{
scanf("%d", &N);
for(int i=1; i<=N; i++) scanf("%lld", &A[i]);
reverse(A+1, A+N+1);
A[0]=INF;
vector<int> S;
S.push_back(0);
for(int i=1; i<=N; i++)
{
while(!S.empty() && A[S.back()]<=A[i]) S.pop_back();
S.push_back(i);
}
for(int i=1; i<S.size(); i++)
{
dp[i]=INF;
for(int j=0; j<i; j++)
{
dp[i]=min(dp[i], dp[j]+A[S[j+1]]*S[i]);
}
}
printf("%lld\n", dp[S.size()-1]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |