제출 #492704

#제출 시각아이디문제언어결과실행 시간메모리
492704zhougzDischarging (NOI20_discharging)C++17
100 / 100
138 ms13928 KiB
/**
 *    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) 메시지

Discharging.cpp: In function 'int main()':
Discharging.cpp:18:11: warning: 'dp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   18 |   return ((double)c - rhs.c) / ((double)rhs.m - m);
      |           ^~~~~~~~~
Discharging.cpp:50:12: note: 'dp' was declared here
   50 |  long long dp;
      |            ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...