제출 #1301455

#제출 시각아이디문제언어결과실행 시간메모리
1301455ProtonDecay314Aliens (IOI16_aliens)C++20
25 / 100
842 ms1114112 KiB
#include "aliens.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<vpll> vvpll; typedef vector<bool> vb; #define INF(dt) numeric_limits<dt>::max() #define fi first #define se second // Create a struct for linear functions // First argument: slope, second argument: y-intercept struct Line { ll m, b, b2; pll evaluate(ll x) const { return {m * x + b, b2}; } }; /* Maintain the minimum line in the li chao tree */ class Tree { public: Tree *lt, *rt; ll l, r; Line v; Tree(ll a_l, ll a_r): lt(nullptr), rt(nullptr), l(a_l), r(a_r), v({0ll, INF(ll), INF(ll)}) {} void build() { if(l == r) { return; } ll m = (l + r) >> 1ll; lt = new Tree(l, m); rt = new Tree(m + 1ll, r); lt->build(); rt->build(); } void insert_line(Line nl) { ll m = (l + r) >> 1ll; bool less_l = nl.evaluate(l) < v.evaluate(l); bool less_m = nl.evaluate(m + 1ll) < v.evaluate(m + 1ll); /* ! TODO why does swap work ! and v = nl does not??? well, if we do v = nl, we simply erase v from existence we don't want that---we want to consider both so nl is considered now therefore we instead propagate v downward */ if(less_m) swap(v, nl); if(l == r) { return; } else if(less_l != less_m) { lt->insert_line(nl); } else { rt->insert_line(nl); } } pll evaluate(ll x) { if(l == r) { return v.evaluate(x); } ll m = (l + r) >> 1ll; if(x <= m) { return min(lt->evaluate(x), v.evaluate(x)); } else { return min(rt->evaluate(x), v.evaluate(x)); } } }; /* Suppose the penalty for using another picture is +y */ pll solve_lambda_brute(const vpll& pts, ll m, ll y) { ll np = pts.size(); // note: stores NEGATIVE area, num pictures // then, the DP just gets the maximum state vpll dp(np, {0ll, 0ll}); Tree tr(0ll, m - 1ll); tr.build(); for(ll i = 0ll; i < np; i++) { ll cl = pts[i].fi, cr = pts[i].se; if(i == 0ll) { tr.insert_line({- (pts[i].fi << 1ll), y + pts[i].fi * pts[i].fi, -1ll}); } else { ll overlap = max(pts[i - 1ll].se - pts[i].fi + 1ll, 0ll); tr.insert_line({- (pts[i].fi << 1ll), dp[i - 1ll].fi - overlap * overlap + y + pts[i].fi * pts[i].fi, dp[i - 1ll].se - 1ll}); } pll opt = tr.evaluate(cr + 1ll); dp[i] = {opt.fi + (cr + 1ll) * (cr + 1ll), opt.se}; // cerr << y << " " << i << " " << dp[i].fi << " " << -dp[i].se << endl; } return dp[np - 1ll]; } ll take_photos(int i_n, int i_m, int i_k, vi r, vi c) { ll n = i_n, m = i_m, k = i_k; // first, we preprocess. remove all redundant points vpll pts; for(ll i = 0ll; i < n; i++) { if(r[i] > c[i]) swap(r[i], c[i]); pts.push_back({r[i], c[i]}); } sort(pts.begin(), pts.end(), [](pll p1, pll p2){return p1.fi < p2.fi || (p1.fi == p2.fi && p1.se > p2.se);}); ll max_r = -1ll; vpll filt_pts; for(ll i = 0ll; i < n; i++) { ll cl = pts[i].fi, cr = pts[i].se; if(cr > max_r) { filt_pts.push_back(pts[i]); // cerr << cl << " " << cr << endl; max_r = cr; } } // Performing lagrangian relaxation ll lo = 0ll, hi = 1e12; while(hi - lo > 1ll) { ll mid = (lo + hi) >> 1ll; pll cpair = solve_lambda_brute(filt_pts, m, mid); ll c_k = -cpair.se; if(c_k >= k) lo = mid; else hi = mid; } return solve_lambda_brute(filt_pts, m, lo).fi - k * lo; }

컴파일 시 표준 에러 (stderr) 메시지

aliens.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
aliens_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#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...