제출 #135582

#제출 시각아이디문제언어결과실행 시간메모리
135582random0029Aliens (IOI16_aliens)C++14
60 / 100
533 ms67052 KiB
// ItnoE #include<bits/stdc++.h> using namespace std; typedef long long ll; struct CHT { typedef pair < ll , ll > Line; vector < pair < ll , Line > > A; ll INF = (ll)1e18; inline void Clear() { A.clear(); } inline void Add(Line X) { while (A.size() && Intersection(A.back().second, X) <= A.back().first) A.pop_back(); if (A.size()) A.push_back({Intersection(A.back().second, X), X}); else A.push_back({-INF, X}); } inline ll GetMax(ll X) { int lb = upper_bound(A.begin(), A.end(), pair < ll , Line > {X, {INF, INF}}) - A.begin() - 1; return (A[lb].second.first * X + A[lb].second.second); } inline ll Intersection(Line X, Line Y) { if (X.first == Y.first && X.second <= Y.second) return (-INF); if (X.first == Y.first) return (INF); return ((X.second - Y.second) / (Y.first - X.first)) + ((X.second - Y.second) % (Y.first - X.first) > 0); } }; const int N = 50004, MXM = 1e6 + 10; int n, m, A[N], B[N], F[N], MN[MXM]; inline ll SQR(ll a) {return (a * a);} int64_t take_photos(int q, int mm, int k, vector < int > RG, vector < int > CG) { m = mm; memset(MN, 63, sizeof(MN)); for (int i = 0; i < q; i ++) { if (RG[i] > CG[i]) swap(RG[i], CG[i]); MN[CG[i]] = min(MN[CG[i]], RG[i]); } for (int i = 0; i < m; i ++) if (MN[i] <= i) { int b = i, a = i - MN[i] + 1; while (n && B[n] - A[n] >= b - a) n --; n ++; B[n] = b; A[n] = a; F[n] = B[n] - A[n]; } CHT C; ll dp[k + 5][n + 5]; memset(dp, 63, sizeof(dp)); for (int i = 0; i <= k; i ++) dp[i][0] = 0; k = min(k, n); for (int j = 1; j <= k; j ++) { C.Clear(); for (int i = 1; i <= n; i ++) { ll vl = dp[j - 1][i - 1] + SQR(F[i]); if (i > 1 && B[i - 1] > F[i]) vl -= SQR(B[i - 1] - F[i]); if (vl <= (ll)(1e16)) C.Add({F[i], - vl}); dp[j][i] = min(dp[j - 1][i], -C.GetMax(2 * B[i]) + SQR(B[i])); } } /*for (int j = 1; j <= k; j ++) { for (int i = 1; i <= n; i ++) { dp[j][i] = dp[j - 1][i]; for (int h = 1; h <= i; h ++) { ll vl = dp[j - 1][h - 1]; vl += SQR(B[i] - B[h] + A[h]); if (h > 1 && B[h - 1] > B[h] - A[h]) vl -= SQR(B[h - 1] - (B[h] - A[h])); dp[j][i] = min(dp[j][i], vl); } } }*/ return (dp[k][n]); } /*int main() { int q = 2;//5; int mm = 6;//7; int k = 2; vector < int > _R = {1, 4};//{0, 4, 4, 4, 4}; vector < int > _C = {4, 1};//{3, 4, 6, 5, 6}; ll Res = take_photos(q, mm, k, _R, _C); cout << Res << endl; }*/
#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...