#include <bits/stdc++.h>
#include "meetings.h"
using namespace std;
vector<long long> minimum_costs(vector<int> H, vector<int> L, vector<int> R) {
int N = H.size();
int Q = L.size();
vector<long long> ans(Q);
if (Q <= 5000 && N <= 5000) {
for (int i = 0; i < Q; i++) {
vector<long long> cost_l(R[i] - L[i] + 2), cost_r(R[i] - L[i] + 2);
stack<pair<int, int>> st;
st.emplace(2e9, R[i] - L[i] + 1);
for (int j = R[i] - L[i]; j >= 0; j--) {
while (st.top().first <= H[j + L[i]]) st.pop();
cost_r[j] = cost_r[st.top().second] + (long long)H[j + L[i]] * (st.top().second - j);
st.emplace(H[j + L[i]], j);
}
while (!st.empty()) st.pop();
st.emplace(2e9, 0);
for (int j = 0; j <= R[i] - L[i]; j++) {
while (st.top().first <= H[j + L[i]]) st.pop();
cost_l[j + 1] = cost_l[st.top().second] + (long long)H[j + L[i]] * (j + 1 - st.top().second);
st.emplace(H[j + L[i]], j + 1);
}
ans[i] = 1e18;
for (int j = 0; j <= R[i] - L[i]; j++) {
ans[i] = min(ans[i], cost_l[j + 1] + cost_r[j] - H[j + L[i]]);
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
159 ms |
792 KB |
Output is correct |
11 |
Correct |
579 ms |
788 KB |
Output is correct |
12 |
Correct |
167 ms |
816 KB |
Output is correct |
13 |
Correct |
553 ms |
788 KB |
Output is correct |
14 |
Correct |
74 ms |
812 KB |
Output is correct |
15 |
Correct |
80 ms |
812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
12 ms |
2264 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
12 ms |
2264 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
159 ms |
792 KB |
Output is correct |
11 |
Correct |
579 ms |
788 KB |
Output is correct |
12 |
Correct |
167 ms |
816 KB |
Output is correct |
13 |
Correct |
553 ms |
788 KB |
Output is correct |
14 |
Correct |
74 ms |
812 KB |
Output is correct |
15 |
Correct |
80 ms |
812 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Incorrect |
12 ms |
2264 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |