제출 #963004

#제출 시각아이디문제언어결과실행 시간메모리
963004penguin133Aliens (IOI16_aliens)C++17
60 / 100
835 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; #include "aliens.h" //#define int long long typedef long long ll; #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<pi>dq; ll f(pi x, ll y){ return x.fi * y + x.se; } long double intersect(ll a, ll b, ll c, ll d){ return (long double)(d-b)/(a-c); } void ins(ll m, ll c){ while(dq.size() > 1){ int s = dq.size(); if(dq[s-1].fi == m){ if(dq[s-1].se < c)dq.pop_back(); else break; continue; } if(intersect(dq[s-1].fi, dq[s-1].se, m, c) <= intersect(dq[s-2].fi, dq[s-2].se, m, c))dq.pop_back(); else break; } dq.push_back({m, c}); } ll query(ll x){ while(dq.size() > 1){ if(f({dq[0].fi, dq[0].se}, x) < f({dq[1].fi, dq[1].se}, x))dq.pop_front(); else break; } return f(dq[0], x); } ll mn[1000005]; pi stuf[1000005]; long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { 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; 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(); } return dp[n - 1][k]; }
#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...