Submission #79687

#TimeUsernameProblemLanguageResultExecution timeMemory
79687LeMansAliens (IOI16_aliens)C++14
0 / 100
3 ms704 KiB
#include "aliens.h" #include <stdio.h> #include <bits/stdc++.h> using namespace std; typedef double db; typedef long long ll; typedef long double ld; typedef unsigned int ui; typedef unsigned long long ull; typedef pair < db, db > pdd; typedef pair < db, ld > pdl; typedef pair < ld, db > pld; typedef pair < ld, ld > ldp; typedef pair < ll, ll > pll; typedef pair < int, ll > pil; typedef pair < ll, int > pli; typedef pair < int, int > pii; #define F first #define S second #define en end() #define bg begin() #define rev reverse #define mp make_pair #define pb push_back #define y1 y1234567890 #define um unordered_map #define all(x) x.bg, x.en #define sz(x) (int)x.size() #define len(x) (int)strlen(x) #define sqr(x) ((x + 0ll) * (x)) #define sqrd(x) ((x + 0.0) * (x)) #define forn(i, n) for (int i = 1; i <= n; i++) const ll inf = (ll)1e18; const ll mod = (ll)1e9 + 7; const db eps = (db)1e-9; const db pi = acos(-1.0); const int dx[] = {0, 0, 1, 0, -1}; const int dy[] = {0, 1, 0, -1, 0}; const int N = 100500; const int M = 1000500; pll line[N]; ll cur[N], dp[N]; int tot, ptr, sz, ar[N], pref[N], pos[N], f[M]; inline db cross(pll l1, pll l2) { return (l2.S - l1.S + 0.0) / (l1.F - l2.F); } inline void add(ll k, ll b) { while (sz >= 2) { if (cross(line[sz - 1], line[sz]) < cross(line[sz - 1], {k, b})) break; sz--; } line[++sz] = {k, b}; ptr = min(ptr, sz); } inline ll get(ll x) { while (ptr < sz && cross(line[ptr], line[ptr + 1]) < x) ptr++; return line[ptr].F * x + line[ptr].S; } ll take_photos(int n, int m, int lim, vector < int > r, vector < int > c) { for (int i = 0; i < n; i++) { int L = min(r[i], c[i]); int R = max(r[i], c[i]); L++, R++; ar[++sz] = L; ar[++sz] = R; f[L] = max(f[L], R); } sort(ar + 1, ar + 1 + tot); tot = unique(ar + 1, ar + 1 + tot) - ar - 1; for (int i = 0; i <= tot; i++) dp[i] = cur[i] = inf; dp[0] = 0; for (int i = 1; i <= tot; i++) { pref[i] = max(pref[i - 1], f[ar[i]]); if (pref[i]) pos[i] = lower_bound(ar + 1, ar + 1 + tot, pref[i]) - ar; } ll ans = inf; for (int j = 1; j <= lim; j++) { int pt = 1; sz = 0; ptr = 1; for (int i = 1; i <= tot; i++) { while (pt <= i && pos[pt - 1] <= i) { add(1 - ar[pt], dp[pos[pt - 1]] + sqr(ar[pt] - 1) - sqr(max(0, ar[pos[pt - 1]] - ar[pt] + 1))); pt++; } if (sz) cur[i] = min(cur[i], get((ar[i] << 1)) + sqr(ar[i])); } if (j == 1) assert(cur[tot] != inf); for (int i = 0; i <= tot; i++) { swap(cur[i], dp[i]); cur[i] = inf; } ans = min(ans, dp[tot]); } return ans; }
#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...