답안 #1099475

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099475 2024-10-11T11:34:11 Z NoMercy Discharging (NOI20_discharging) C++17
0 / 100
32 ms 7760 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAXN = 2e5 + 55;

int dp[MAXN], T[MAXN];

int f (array<int, 2> line, int x) {
	return line[0] * x + line[1];
}
long double intersect (array<int, 2> line1, array<int, 2> line2) {
	return (line2[1] - line1[1]) / (line1[0] - line2[0]);
}
struct Hull {
	deque <array<int, 2>> dq;
	int query (int x) {
		while ((int)dq.size() > 1 && f(dq[0], x) > f(dq[1], x)) dq.pop_front();
		return f(dq[0], x);
	}
	void insert (array<int, 2> line) {
		while (dq.size() > 1 && intersect(line, dq.back()) <= intersect(line, dq[dq.size() - 2])) dq.pop_back();
		dq.push_back(line);
	}
};

int32_t main () {

    ios_base::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0); 

    int N;
    cin >> N;
	for (int i = 1;i <= N;i ++) {
        cin >> T[i];
    }

    Hull hl;
	int mx = 1, ind = 1;
	for (int i = 1;i <= N;i ++) {
		if (T[i] >= T[mx]) {
            mx = i;
        }
		while (ind <= mx){
			hl.insert({-ind, dp[ind - 1]});
			ind ++;
		}
		if (i > 1) {
            dp[i] = min(T[mx] * N, hl.query(T[mx]) + T[mx] * (N + 1));
        } else {
            dp[i] = T[1] * N;
        }
	}
	cout << dp[N] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 32 ms 7760 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -