Submission #963002

#TimeUsernameProblemLanguageResultExecution timeMemory
963002penguin133Aliens (IOI16_aliens)C++17
25 / 100
2045 ms15676 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<pair<ll, ll> > dq; ll f(pi x, ll y){ return x.first*y + x.second; } 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(intersect(dq.back().first, dq.back().second,m,c) <= intersect(dq[s-2].first, dq[s-2].second, m,c))dq.pop_back(); else break; } dq.push_back(make_pair(m,c)); } ll query(ll x){ while(dq.size() > 1){ if(f(dq[0], x) < f(dq[1], 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...