Submission #79649

#TimeUsernameProblemLanguageResultExecution timeMemory
79649LeMansAliens (IOI16_aliens)C++14
4 / 100
10 ms1148 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 = 50050; const int M = 1000500; ll dp[N][105]; int sz, ar[N], pref[N], pos[N], f[M], p[N][105]; void rec(int l, int r, int optL, int optR, int j) { int mid = (l + r) >> 1; for (int k = optL; k <= min(mid, optR); k++) { int mustpos = pos[k - 1]; if (mustpos > mid) continue; ll trash = (mustpos >= k ? sqr(ar[mustpos] - ar[k] + 1) : 0); if (dp[mustpos][j - 1] + sqr(ar[mid] - ar[k] + 1) - trash < dp[mid][j]) { dp[mid][j] = dp[mustpos][j - 1] + sqr(ar[mid] - ar[k] + 1) - trash; p[mid][j] = k; } } if (l != r) { rec(l, mid, optL, p[mid][j], j); rec(mid + 1, r, p[mid][j], optR, j); } } 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 + sz); sz = unique(ar + 1, ar + 1 + sz) - ar - 1; for (int i = 0; i <= sz; i++) for (int j = 0; j <= lim; j++) dp[i][j] = inf; dp[0][0] = 0; for (int i = 1; i <= sz; i++) { pref[i] = max(pref[i - 1], f[ar[i]]); if (pref[i]) pos[i] = lower_bound(ar + 1, ar + 1 + sz, pref[i]) - ar; } for (int i = 1; i <= lim; i++) rec(1, sz, 1, sz, i); ll ans = inf; for (int i = 1; i <= lim; i++) ans = min(ans, dp[sz][i]); 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...