Submission #1099478

# Submission time Handle Problem Language Result Execution time Memory
1099478 2024-10-11T11:39:09 Z NoMercy Discharging (NOI20_discharging) C++17
20 / 100
73 ms 25724 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAXN = 1e6 + 55;

ll dp[MAXN], T[MAXN];

int f (array<ll, 2> line, int x) {
	return line[0] * x + line[1];
}
long double intersect (array<ll, 2> line1, array<ll, 2> line2) {
	return (line2[1] - line1[1]) / (line1[0] - line2[0]);
}
struct Hull {
	deque<array<ll, 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<ll, 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;
	ll mx = 1;
    int ind = 1;
	for (int i = 1;i <= N;i ++) {
		if (T[i] >= T[mx]) {
            mx = i;
        }
		while (ind <= mx){
			hl.insert({-1LL * 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";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 0 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 65 ms 15960 KB Output is correct
2 Correct 68 ms 25688 KB Output is correct
3 Correct 69 ms 25720 KB Output is correct
4 Correct 73 ms 25556 KB Output is correct
5 Correct 71 ms 25680 KB Output is correct
6 Correct 72 ms 25692 KB Output is correct
7 Correct 68 ms 25596 KB Output is correct
8 Correct 70 ms 25584 KB Output is correct
9 Correct 73 ms 25724 KB Output is correct
10 Correct 68 ms 25668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 0 ms 352 KB Output is correct
15 Incorrect 1 ms 356 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 0 ms 352 KB Output is correct
15 Incorrect 1 ms 356 KB Output isn't correct
16 Halted 0 ms 0 KB -