Submission #736101

#TimeUsernameProblemLanguageResultExecution timeMemory
736101PenguinsAreCuteDischarging (NOI20_discharging)C++17
100 / 100
429 ms24012 KiB
// "Complex numbers are better than pears." // "Always use complex numbers when possible." // "And plus real numbers are complex numbers anyway so you'll be using them." // "69 is the largest number you can factorial on a calculator." // "Therefore, always make your code 69 lines if possible." // - Some Y1 Rafflesian #include <bits/stdc++.h> using namespace std; #define int long long #define re real() #define im imag() #define mp make_pair #define pb push_back #define speed ios_base::sync_with_stdio(false); cin.tie(0) #define stMx(a,b) a = max(a,b) #define stMn(a,b) a = min(a,b) typedef complex<int> ii; typedef vector<int> vi; typedef set<int> si; typedef vector<ii> vii; typedef set<ii> sii; #define REP(i, a, b) for(int i = a; i < b; i++) #define float long double deque<ii> dq; int f(ii line, int x) { return line.re * x + line.im; } int query(int x) { while(dq.size() > 1) { if(f(dq[0], x) < f(dq[1], x)) dq.pop_front(); else break; } return f(dq[0], x); } float intersect(int a, int b, int c, int d) { return (float)(d - b) / (a - c); } float intersect(ii p1, ii p2) { return intersect(p1.re, p1.im, p2.re, p2.im); } void ins(int m, int c) { ii line = ii(m, c); while(dq.size() > 1) { int s = dq.size(); if(intersect(dq[s - 1], line) <= intersect(dq[s - 2], line)) dq.pop_back(); else break; } dq.push_back(line); } int32_t main() { int N; cin >> N; int T[N], pre[N], nd[N], dp[N]; cin >> T[0]; pre[0] = T[0]; REP(i, 1, N) { cin >> T[i]; pre[i] = max(T[i], pre[i-1]); } ins(-1 * N, 0); REP(i, 0, N) { if(i == 0 || pre[i - 1] < T[i]) { dp[i] = -1 * query(T[i]); int ptr = i; while(ptr < N && T[ptr] <= T[i]) ptr++; ins(ptr - N, -1 * dp[i]); } else { dp[i] = dp[i - 1]; } } cout << dp[N-1]; }

Compilation message (stderr)

Discharging.cpp: In function 'int32_t main()':
Discharging.cpp:51:40: warning: unused variable 'nd' [-Wunused-variable]
   51 |     int N; cin >> N; int T[N], pre[N], nd[N], dp[N];
      |                                        ^~
#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...