제출 #574030

#제출 시각아이디문제언어결과실행 시간메모리
574030vovamrAliens (IOI16_aliens)C++17
41 / 100
2068 ms4788 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define fi first #define se second #define ll long long #define ld long double #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define pb push_back #define mpp make_pair #define ve vector using namespace std; using namespace __gnu_pbds; template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; const ll inf = 1e18; const int iinf = 1e9; typedef pair<ll, ll> pll; typedef pair<int, int> pii; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); } template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); } inline bool in(const pii &a, const pii &b) { auto &[l1, r1] = b; auto &[l2, r2] = a; return (l2 >= l1 && r2 <= r1); } inline int is(const pii &a, const pii &b) { auto &[l1, r1] = a; auto &[l2, r2] = b; return max(0, min(r1, r2) - max(l1, l2) + 1); } struct line { ll k, b, id; line() : k(0), b(0) {} line(ll k, ll b, ll id) : k(k), b(b), id(id) {} inline pll operator()(const ll &x) { return mpp(k * x + b, id); } }; inline bool bad(const line &a, const line &b, const line &c) { return (a.b - c.b) * (b.k - a.k) > (a.b - b.b) * (c.k - a.k); } deque<line> s; inline void add(const line &c) { if (1) return void(s.push_front(c)); while (sz(s) >= 2) { line &a = s[1], &b = s[0]; if (bad(c, b, a)) s.pop_front(); else break; } s.push_front(c); } inline pll qry(const ll &x) { pll res = {inf, inf}; for (auto &cr : s) chmin(res, cr(x)); return res; } ll take_photos(int n, int m, int k, ve<int> R, ve<int> C) { ve<pii> pts(n); for (int i = 0; i < n; ++i) pts[i] = {min(R[i], C[i]), max(R[i], C[i])}; sort(all(pts), [](const pii &a, const pii &b) { return mpp(a.se, a.fi) < mpp(b.se, b.fi); }); pts.erase(unique(all(pts)), pts.end()); ve<pii> nw; for (int i = sz(pts) - 1; ~i; --i) { if (!sz(nw) || !in(pts[i], nw.back())) nw.pb(pts[i]); } pts.swap(nw); reverse(all(pts)); n = sz(pts); ve<ll> isec(n); for (int i = 1; i < n; ++i) isec[i] = is(pts[i - 1], pts[i]); for (int i = 0; i < n; ++i) isec[i] *= isec[i]; ve<int> l(n), r(n); for (int i = 0; i < n; ++i) l[i] = pts[i].fi, r[i] = pts[i].se + 1; auto ok = [&](ll u) { s.clear(); ve<pll> dp(n, {inf, inf}); for (int i = 0; i < n; ++i) { add(line(2 * l[i], (!i ? 0 : dp[i - 1].fi) - isec[i] + l[i] * 1ll * l[i], !i ? 0 : dp[i - 1].se)); auto need = qry(-r[i]); chmin(dp[i], {need.fi + u + r[i] * 1ll * r[i], need.se + 1}); // (u + r[i]^2) - (2l[j]) * r[i] + (l[j]^2 + dp[j - 1] - isec[j]); /** for (int j = 0; j <= i; ++j) { ll val = (r[i] - l[j]) * 1ll * (r[i] - l[j]); // (r[i]^2 + u) - 2l[j + 1] * r[i] + (l[j + 1]^2 - isec[j] + dp[j].fi) val += -isec[j] + u + (!j ? 0 : dp[j - 1].fi); chmin(dp[i], mpp(val, (!j ? 0 : dp[j - 1].se) + 1)); } */ } return dp[n - 1]; }; /* ve<ve<ll>> dp(n, ve<ll> (k + 1, inf)); for (int i = 0; i < n; ++i) dp[i][1] = (r[i] - l[0]) * 1ll * (r[i] - l[0]); for (int j = 2; j <= k; ++j) { for (int i = 0; i < n; ++i) chmin(dp[i][j], dp[i][j - 1]); for (int i = 0; i < n; ++i) { for (int z = 0; z <= i; ++z) { ll val = (!z ? 0 : dp[z - 1][j - 1]); val += r[i] * r[i] + l[z] * l[z] - 2 * r[i] * l[z]; val -= isec[z]; chmin(dp[i][j], val); } } } return dp[n - 1][k]; */ ll le = 0, re = m * 1ll * m + 228, mid; ll ans = re; while (le <= re) { mid = le + re >> 1; ok(mid).se <= k ? ans = mid, re = mid - 1 : le = mid + 1; } return ok(ans).fi - ans * k; } #ifdef LOCAL int main() { int n, m, k; assert(3 == scanf("%d %d %d", &n, &m, &k)); std::vector<int> r(n), c(n); for (int i = 0; i < n; i++) { assert(2 == scanf("%d %d", &r[i], &c[i])); } long long ans = take_photos(n, m, k, r, c); printf("%lld\n", ans); return 0; } #endif

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

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:113:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  113 |   mid = le + re >> 1;
      |         ~~~^~~~
#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...