제출 #959296

#제출 시각아이디문제언어결과실행 시간메모리
959296ThegeekKnight16Aliens (IOI16_aliens)C++17
4 / 100
1 ms436 KiB
#include <bits/stdc++.h> #include "aliens.h" using namespace std; typedef long long ll; 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 + 1) * (v[r].second - v[l].first + 1) - (sIni[r] - sIni[l-1] + inter[l-1]);}; vector<vector<ll>> dp(N+1, vector<ll>(K+1)); for (int k = 1; k <= K; k++) { for (int i = 1; i <= N; i++) { if (i <= k) {dp[i][k] = 0; continue;} dp[i][k] = 0x3f3f3f3f3f3f3f3f; for (int j = 1; j <= i; j++) dp[i][k] = min(dp[i][k], dp[j-1][k-1] + C(j, i)); } } return dp[N][K] + sIni[N]; }
#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...