| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 1265882 | mingga | Discharging (NOI20_discharging) | C++20 | 74 ms | 16088 KiB | 
// Author: caption_mingle
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 1e6 + 7;
int n, a[N], dp[N];
double ite(pair<double, double> A, pair<double, double> B) {
	// cerr << A.fi << ' ' << A.se << ' ' << B.fi << ' ' << B.se << ln;
	return double(B.se - A.se) / (A.fi - B.fi);
}
bool bad(pair<double, double> A, pair<double, double> B, pair<double, double> C) {
	return ite(A, B) >= ite(A, C);
}
signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	#define task ""
	if(fopen(task ".INP", "r")) {
		freopen(task ".INP", "r", stdin);
		freopen(task ".OUT", "w", stdout);
	}
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	deque<pair<double, double>> hull;
	hull.pb({n, 0});
	int mx = 0;
	for(int i = 1; i <= n; i++) {
		mx = max(mx, a[i]);
		while(sz(hull) >= 2) {
			if(ite(hull[0], hull[1]) <= mx) hull.pop_front();
			else break;
		}
		dp[i] = hull[0].fi * mx + hull[0].se;
		while(sz(hull) >= 2) {
			if(bad(hull[sz(hull) - 2], hull.back(), make_pair(n - i, dp[i]))) hull.pop_back();
			else break;
		}
		// cerr << n - i << ' ' << dp[i] << ln;
		hull.pb({n - i, dp[i]});
	}
	cout << dp[n] << ln;
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
컴파일 시 표준 에러 (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... | ||||
