# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
270444 | doowey | Discharging (NOI20_discharging) | C++14 | 203 ms | 14840 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
struct Line{
ld ai;
ld bi;
ld ti;
};
ld intersect(Line t1, Line t2){
return (t2.bi-t1.bi)/(t1.ai-t2.ai);
}
vector<Line> hull;
void add_line(Line nw){
while(hull.size() >= 2 && intersect(hull[hull.size() - 2], nw) <= intersect(hull[hull.size() - 2],hull[hull.size() - 1])){
hull.pop_back();
}
if(!hull.empty())
hull.back().ti = intersect(hull.back(), nw);
hull.push_back(nw);
}
ll get(ll x){
int li = 0, ri = hull.size() - 1;
int mid;
while(li < ri){
mid = (li + ri) / 2;
if(hull[mid].ti < x)
li = mid + 1;
else
ri = mid;
}
return hull[li].ai * x + hull[li].bi;
}
const int N = (int)1e6 + 10;
ll dp[N];
int main(){
fastIO;
int n;
cin >> n;
ll a, x=0ll;
add_line({-n,0,(ll)1e18});
ll vl;
for(int i = 1; i <= n; i ++ ){
cin >> a;
x = max(x, a);
vl = get(x);
dp[i]=-vl;
add_line({-(n-i), -dp[i], (ll)1e18});
}
cout << dp[n] << "\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... |