Submission #962435

#TimeUsernameProblemLanguageResultExecution timeMemory
962435RaresFelixAliens (IOI16_aliens)C++17
4 / 100
2 ms600 KiB
#include <bits/stdc++.h> #include "aliens.h" //#pragma GCC optimize("O3") //#pragma GCC target("avx,avx2,fma") #define sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; using ll = long long; using ld = long double; // or double, if TL is tight using str = string; using ii = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; const ll INF = 1e16; struct CHT { int p = 0; vector<pl> V; void insert(ll a, ll b) { /// add ax + b while(V.size() > 1) { auto [a1, b1] = V.end()[-2]; auto [a2, b2] = V.end()[-1]; if((b1 - b2) * (a - a2) >= (b2 - b) * (a2 - a1)) { V.pop_back(); } else break; } V.push_back({a, b}); } ll query(ll x) { if(V.empty()) return INF; auto eval = [&](pl f) { return f.first * x + f.second; }; while(p + 1 < V.size() && eval(V[p]) >= eval(V[p + 1])) ++p; return eval(V[p]); } }; ll take_photos(int n0, int m, int k, vi r, vi c) { vector<ii> SegInit; for(int i = 0; i < n0; ++i) { SegInit.push_back({min(r[i], c[i]), max(r[i], c[i]) + 1}); } sort(all(SegInit), [&](auto a, auto b) { if(a.first != b.first) return a < b; return a > b; }); vector<ii> Seg; int cur_dr = -1; for(auto [st, dr] : SegInit) { if(dr <= cur_dr) continue; else { Seg.push_back({st, dr}); cur_dr = dr; } } int n = Seg.size(); vll st(n, 0), dr(n, 0), sb(n, 0); for(int i = 0; i < n; ++i) { st[i] = Seg[i].first; dr[i] = Seg[i].second; sb[i] = (dr[i] - st[i]) * (dr[i] - st[i]); if(i) { if(dr[i - 1] > st[i]) sb[i] -= (dr[i - 1] - st[i]) * (dr[i - 1] - st[i]); sb[i] += sb[i - 1]; } } auto cost = [&](int i, int j) { return (dr[j] - st[i]) * (dr[j] - st[i]) - (dr[i] - st[i]) * (dr[i] - st[i]) - sb[j] + sb[i]; return (dr[j] * dr[j] - sb[j]) + (2 * st[i] * dr[i] - dr[i] * dr[i] + sb[i]) - 2 * st[i] * dr[j]; }; ll re0 = sb.back(); auto t = [&](ld lambda) { ld re = - lambda * k; CHT Sol; vector<ld> DP(n, 0.); for(int i = 0; i < n; ++i) { ld dpant = 0.; if(i) dpant = DP[i - 1]; Sol.insert(- 2 * st[i], (dpant + (2 * st[i] * dr[i] - dr[i] * dr[i] + sb[i]))); DP[i] = lambda + cost(0, i); ld v = lambda + (Sol.query(dr[i]) + dr[i] * dr[i] - sb[i]); DP[i] = min(DP[i], v); } return DP.back() - lambda * k; }; ld re = 0; ld s = 0, d = 1e6, mij; const ld EPS = 1e-8; ld vm = 0; while(d - s > EPS) { ld m1 = (2 * s + d) / 3, v1 = t(m1); ld m2 = (s + 2 * d) / 3, v2 = t(m2); vm = max(vm, v1); vm = max(vm, v2); if(v1 < v2) s = m1; else d = m2; } re = ll(round(vm) + EPS); re += re0; return re; }

Compilation message (stderr)

aliens.cpp: In member function 'll CHT::query(ll)':
aliens.cpp:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         while(p + 1 < V.size() && eval(V[p]) >= eval(V[p + 1])) ++p;
      |               ~~~~~~^~~~~~~~~~
aliens.cpp: In lambda function:
aliens.cpp:83:12: warning: unused variable 're' [-Wunused-variable]
   83 |         ld re = - lambda * k;
      |            ^~
aliens.cpp: In function 'll take_photos(int, int, int, vi, vi)':
aliens.cpp:100:24: warning: unused variable 'mij' [-Wunused-variable]
  100 |     ld s = 0, d = 1e6, mij;
      |                        ^~~
#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...