# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
287948 | PeppaPig | Discharging (NOI20_discharging) | C++14 | 173 ms | 8232 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define long long long
using namespace std;
const int N = 1e6 + 5;
struct CHT {
struct line {
long m, c;
line(long m, long c) : m(m), c(c) {}
long f(long x) { return m * x + c; }
};
int ptr = 0;
vector<line> vec;
bool bad(line a, line b, line c) {
return (c.c - a.c) * (a.m - b.m) <= (b.c - a.c) * (a.m - c.m);
}
void add(long m, long c) {
line l(m, c);
while(vec.size() > 1 && bad(vec[(int)vec.size() - 2], vec.back(), l))
vec.pop_back();
vec.emplace_back(l);
}
long get_ans(long x) {
if(ptr >= (int)vec.size()) ptr = (int)vec.size() - 1;
while(ptr + 1 < (int)vec.size() && vec[ptr + 1].f(x) < vec[ptr].f(x))
++ptr;
return vec[ptr].f(x);
}
} hull;
int n;
long A[N], dp[N];
vector<int> stk;
int main() {
scanf("%d", &n);
for(int i = n; i; i--) scanf("%lld", A + i);
A[0] = 1e18;
stk.emplace_back(0);
for(int i = 1; i <= n; i++) {
while(!stk.empty() && A[stk.back()] <= A[i])
stk.pop_back();
stk.emplace_back(i);
}
for(int i = 1; i < (int)stk.size(); i++) {
hull.add(A[stk[i]], dp[i - 1]);
dp[i] = hull.get_ans(stk[i]);
}
printf("%lld\n", dp[(int)stk.size() - 1]);
return 0;
}
컴파일 시 표준 에러 (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... |