Submission #622821

#TimeUsernameProblemLanguageResultExecution timeMemory
622821AlexandruabcdeAliens (IOI16_aliens)C++14
25 / 100
2069 ms16980 KiB
#include "aliens.h" #include <bits/stdc++.h> using namespace std; constexpr int NMAX = 1e6 + 5; struct Interval { int st, dr; bool operator < (const Interval &other) const { return (st < other.st || (st == other.st && dr > other.dr)); } }; int N, M, K; Interval V[NMAX]; long long Cost (int a, int b) { return 1LL * (b-a+1) * (b-a+1); } void Comprim () { sort(V+1, V+N+1); vector <Interval> aux; for (int i = 1; i <= N; ++ i ) { if (aux.empty()) { aux.push_back(V[i]); continue; } if (aux.back().dr < V[i].dr) aux.push_back(V[i]); } N = aux.size(); for (int i = 1; i <= N; ++ i ) V[i] = aux[i-1]; } long long dp[4005][4005]; void Solve_Dp () { for (int j = 1; j <= K; ++ j ) { for (int i = 1; i <= N; ++ i ) { dp[i][j] = Cost(V[1].st, V[i].dr); if (j == 1) continue; ///iau doar i dp[i][j] = min(dp[i][j], dp[i-1][j-1] + Cost(V[i].st, V[i].dr)); for (int c = i-1; c >= 1; -- c ) { int p = V[c+1].st; int new_capat = V[c].dr; dp[i][j] = min(dp[i][j], dp[c][j-1] + Cost(p, V[i].dr) - (p <= new_capat ? Cost(p, new_capat) : 0)); } } } } long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { N = n; M = m; K = k; for (int i = 1; i <= N; ++ i ) { V[i].st = min(r[i-1], c[i-1]); V[i].dr = max(r[i-1], c[i-1]); } Comprim(); Solve_Dp(); return dp[N][K]; }
#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...