제출 #959715

#제출 시각아이디문제언어결과실행 시간메모리
959715ThegeekKnight16Aliens (IOI16_aliens)C++17
60 / 100
1462 ms1048576 KiB
#include <bits/stdc++.h> #include "aliens.h" using namespace std; typedef long long ll; vector<ll> A, B; int tam = 0, pos = 0; bool inutil(int novo, int atual, int velho) { return ((B[velho] - B[novo])*(A[atual] - A[velho]) <= (B[velho] - B[atual])*(A[novo] - A[velho])); } void update(ll newA, ll newB) { A.push_back(newA); B.push_back(newB); ++tam; while (tam > 2 && inutil(tam-1, tam-2, tam-3)) {A.erase(A.end()-2); B.erase(B.end()-2); --tam;} } ll query(ll x) { if (pos >= tam) pos = tam-1; while (pos < tam-1 && (A[pos]*x + B[pos]) >= (A[pos+1]*x + B[pos+1])) ++pos; return (A[pos]*x + B[pos]); } ll take_photos(int N, int M, int K, std::vector<int> r, std::vector<int> c) { vector<pair<ll, ll>> v(N); for (int i = 0; i < N; i++) { int Y = r[i], X = c[i]; if (X > Y) swap(X, Y); v[i] = make_pair(X, Y); } sort(v.begin(), v.end(), [&](const pair<int, int> &a, const pair<int, int> &b) {return (a.first == b.first ? a.second < b.second : a.first > b.first);}); vector<pair<ll, ll>> pareto; for (auto [X, Y] : v) { while (!pareto.empty() && pareto.back().second <= Y) pareto.pop_back(); pareto.emplace_back(X, Y); } v = pareto; reverse(v.begin(), v.end()); //So pra ficar ordenado por X N = v.size(); v.insert(v.begin(), make_pair(-1, -1)); vector<ll> sIni(N+1), inter(N+1); for (int i = 1; i < N; i++) inter[i] = (v[i+1].first > v[i].second ? 0 : (v[i].second - v[i+1].first + 1)*(v[i].second - v[i+1].first + 1)); for (int i = 1; i <= N; i++) sIni[i] = (v[i].second - v[i].first + 1)*(v[i].second - v[i].first + 1) + sIni[i-1] - inter[i-1]; //Ate aqui estou so reduzindo o problema auto C = [&](int l, int r) {return ((v[r].second - v[l].first + 1LL) * (v[r].second - v[l].first + 1LL)) - (sIni[r] - sIni[l-1] + inter[l-1]);}; vector<vector<ll>> dp(N+1, vector<ll>(K+1, 0x3f3f3f3f3f3f3f3f)); fill(dp[0].begin(), dp[0].end(), 0); for (int k = 1; k <= K; k++) { A.clear(); B.clear(); tam = pos = 0; for (int i = 1; i <= N; i++) { update(-2*v[i].first, (v[i].first*v[i].first) - 2*v[i].first + sIni[i-1] - inter[i-1] + dp[i-1][k-1]); dp[i][k] = ((v[i].second + 1)*(v[i].second + 1)) - sIni[i] + query(v[i].second); } } return dp[N][K] + sIni[N]; }

컴파일 시 표준 에러 (stderr) 메시지

aliens.cpp: In function 'll take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:50:10: warning: variable 'C' set but not used [-Wunused-but-set-variable]
   50 |     auto C = [&](int l, int r) {return ((v[r].second - v[l].first + 1LL) * (v[r].second - v[l].first + 1LL)) - (sIni[r] - sIni[l-1] + inter[l-1]);};
      |          ^
#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...