# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
287942 | 2020-09-01T07:06:56 Z | PeppaPig | Discharging (NOI20_discharging) | C++14 | 195 ms | 4344 KB |
#include <bits/stdc++.h> #define long long long using namespace std; const int N = 1e6 + 5; struct CHT { struct line { long m, c; line(long m, long c) : m(m), c(c) {} long f(long x) { return m * x + c; } }; int ptr = 0; vector<line> vec; bool bad(line a, line b, line c) { return (c.c - a.c) * (a.m - b.m) <= (b.c - a.c) * (a.m - c.m); } void add(long m, long c) { line l(m, c); while(vec.size() > 1 && bad(vec[(int)vec.size() - 2], vec.back(), l)) vec.pop_back(); vec.emplace_back(l); } long get_ans(long x) { while(ptr + 1 < (int)vec.size() && vec[ptr + 1].f(x) < vec[ptr].f(x)) ++ptr; return vec[ptr].f(x); } } hull; int n, A[N]; long dp[N]; vector<int> stk; int main() { scanf("%d", &n); for(int i = n; i; i--) scanf("%d", A + i); for(int i = 1; i <= n; i++) { while(!stk.empty() && A[stk.back()] <= A[i]) stk.pop_back(); stk.emplace_back(i); } for(int i = 0; i < (int)stk.size(); i++) { hull.add(A[stk[i]], dp[i - 1]); dp[i] = hull.get_ans(stk[i]); } printf("%lld\n", dp[(int)stk.size() - 1]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 0 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 256 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 0 ms | 256 KB | Output is correct |
10 | Correct | 0 ms | 384 KB | Output is correct |
11 | Correct | 0 ms | 256 KB | Output is correct |
12 | Correct | 0 ms | 384 KB | Output is correct |
13 | Correct | 0 ms | 256 KB | Output is correct |
14 | Correct | 1 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 184 ms | 4224 KB | Output is correct |
2 | Correct | 195 ms | 4164 KB | Output is correct |
3 | Correct | 180 ms | 4216 KB | Output is correct |
4 | Correct | 180 ms | 4216 KB | Output is correct |
5 | Correct | 183 ms | 4216 KB | Output is correct |
6 | Correct | 183 ms | 4344 KB | Output is correct |
7 | Correct | 180 ms | 4216 KB | Output is correct |
8 | Correct | 182 ms | 4220 KB | Output is correct |
9 | Correct | 188 ms | 4328 KB | Output is correct |
10 | Correct | 182 ms | 4216 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 0 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 256 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 0 ms | 256 KB | Output is correct |
10 | Correct | 0 ms | 384 KB | Output is correct |
11 | Correct | 0 ms | 256 KB | Output is correct |
12 | Correct | 0 ms | 384 KB | Output is correct |
13 | Correct | 0 ms | 256 KB | Output is correct |
14 | Correct | 1 ms | 256 KB | Output is correct |
15 | Incorrect | 1 ms | 384 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 0 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 256 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 0 ms | 256 KB | Output is correct |
10 | Correct | 0 ms | 384 KB | Output is correct |
11 | Correct | 0 ms | 256 KB | Output is correct |
12 | Correct | 0 ms | 384 KB | Output is correct |
13 | Correct | 0 ms | 256 KB | Output is correct |
14 | Correct | 1 ms | 256 KB | Output is correct |
15 | Incorrect | 1 ms | 384 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |