# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
492704 | zhougz | Discharging (NOI20_discharging) | C++17 | 138 ms | 13928 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* author: chowgz
* created: 14/03/2021 11:20:55
**/
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = (int)1e6;
struct Line {
int m;
long long c;
long long operator()(int x) {
return (long long)m * x + c;
}
double operator^(const Line &rhs) {
return ((double)c - rhs.c) / ((double)rhs.m - m);
}
};
struct ConvexHull {
Line lines[MAXN + 1];
int l = 0, r = 0;
void operator+=(Line line) {
while (r - l >= 2 && (line ^ lines[r - 1]) <= (lines[r - 1] ^ lines[r - 2])) {
r--;
}
lines[r] = line;
r++;
}
long long operator()(int x) {
while (r - l >= 2 && lines[l](x) >= lines[l + 1](x)) {
l++;
}
return lines[l](x);
}
} hull;
// For more comments, check original cpp file!
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
long long dp;
int maxx = 0;
hull += Line{0, 0};
for (int i = 1; i <= n; i++) {
if (arr[i - 1] > maxx) {
maxx = arr[i - 1];
dp = n * (long long)maxx + hull(maxx);
}
hull += Line{-i, dp};
}
cout << dp << '\n';
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... |