제출 #963156

#제출 시각아이디문제언어결과실행 시간메모리
963156penguin133Aliens (IOI16_aliens)C++17
4 / 100
2 ms4696 KiB
#include <bits/stdc++.h> using namespace std; #include "aliens.h" //#define int long long typedef long long ll; using ld = long long; #define pi pair<ll, ll> #define pii pair<int, pi> #define fi first #define se second #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); deque<pii>dq; ld f(pi x, ll y){ return x.fi * y + x.se; } long double intersect(int a, ld b, int c, ld d){ return (long double)(d-b)/(a-c); } void ins(ll m, ld c, ll in){ while(dq.size() > 1){ int s = dq.size(); if(dq[s-1].fi == m){ if(dq[s-1].se.fi < c)dq.pop_back(); else if(dq[s - 1].se.fi == c && dq[s - 1].se.se > in)dq.pop_back(); else break; continue; } if(make_pair(intersect(dq[s-1].fi, dq[s-1].se.fi, m, c), -dq[s - 1].se.se) <= make_pair(intersect(dq[s-2].fi, dq[s-2].se.fi, m, c), dq[s - 2].se.se))dq.pop_back(); else break; } dq.push_back({m, {c, in}}); } pi query(ll x){ while(dq.size() > 1){ if(make_pair(f({dq[0].fi, dq[0].se.fi}, x), -dq[0].se.se) < make_pair(f({dq[1].fi, dq[1].se.fi}, x), -dq[1].se.se))dq.pop_front(); else break; } return {f({dq[0].fi, dq[0].se.fi}, x), dq[0].se.se}; } ll mn[1000005], val[100005], N; pi dp[100005]; pair <ll, ll> stuf[1000005]; pi cst(ld x){ dq.clear(); for(int i = 0; i < N; i++){ ins(mn[i] * 2, -((i ? dp[i - 1].fi : 0) - 2 * mn[i] + mn[i] * mn[i] - (i ? max(0ll, stuf[i - 1].fi - mn[i] + 1) * (stuf[i - 1].fi - mn[i] + 1) : 0)), (i ? dp[i - 1].se : 0)); pi res = query(stuf[i].fi); res.fi = -res.fi; res.fi += stuf[i].fi * stuf[i].fi + 2 * stuf[i].fi + 1; res.fi += x; res.se++; dp[i] = res; } return dp[N - 1]; } long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { N = n; for(int i = 0; i <= m; i++)mn[i] = 1e18; for(int i = 0; i < n; i++){ if(r[i] > c[i])swap(r[i], c[i]); mn[c[i]] = min(mn[c[i]], (ll)r[i]); stuf[i] = {c[i], r[i]}; } sort(stuf, stuf + n); for(int i = 0; i < n; i++)mn[i] = stuf[i].se, val[i] = 1e18; val[n] = 1e18; for(int i = n - 2; i >= 0; i--)mn[i] = min(mn[i], mn[i + 1]); //return 0; /* ll dp[n + 1][k + 1]; for(int i = 0; i <= n; i++)dp[i][0] = 1e18; for(int j = 1; j <= k; j++){ for(int i = 0; i < n; i++){ ins(mn[i] * 2, -((i ? dp[i - 1][j - 1] : 0) - 2 * mn[i] + mn[i] * mn[i] - (i ? max(0ll, stuf[i - 1].fi - mn[i] + 1) * (stuf[i - 1].fi - mn[i] + 1) : 0))); dp[i][j] = -query(stuf[i].fi) + stuf[i].fi * stuf[i].fi + 2 * stuf[i].fi + 1; dp[i][j] = 1e18; for(int a = i; a >= 0; a--){ dp[i][j] = min(dp[i][j], (a ? dp[a - 1][j - 1] - max(0ll, stuf[a - 1].fi - mn[a] + 1) * (stuf[a - 1].fi - mn[a] + 1) : 0) + (stuf[i].fi - mn[a] + 1) * (stuf[i].fi - mn[a] + 1)); } //cout << dp[i][j] << ' '; } //cout << '\n'; dq.clear(); } */ ld lo = 0, hi = 1e18; ld ans = 1e18; while(lo + 1 < hi){ ld mid = (lo + hi) / 2; pi res = cst(mid); if(res.se <= k)ans = min(ans, res.fi - mid * res.se); if(res.se > k)lo = mid; else hi = mid; } pi res = cst(hi); return res.fi - hi * res.se; }
#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...