Submission #962524

#TimeUsernameProblemLanguageResultExecution timeMemory
962524MinaRagy06Aliens (IOI16_aliens)C++17
25 / 100
2060 ms6748 KiB
#include <bits/stdc++.h> #include "aliens.h" #ifdef MINA #include "grader.cpp" #endif using namespace std; #define ll long long #define sz(x) (int) x.size() ll take_photos(int n, int crap, int m, vector<int> R, vector<int> C) { array<ll, 2> a[n + 1]; vector<ll> v; for (int i = 1; i <= n; i++) { a[i] = {R[i - 1], C[i - 1]}; if (a[i][0] > a[i][1]) swap(a[i][0], a[i][1]); } sort(a + 1, a + n + 1); ll dp[m + 1][n + 1]; memset(dp, '?', sizeof dp); for (int j = 0; j <= m; j++) { dp[j][0] = 0; } ll prf[n + 2]{}; prf[1] = -1e18; for (int i = 1; i <= n; i++) { prf[i + 1] = max(prf[i], a[i][1]); a[i][0]--; prf[i] = max(prf[i], a[i][0]); } for (int j = 1; j <= m; j++) { for (int i = 1; i <= n; i++) { ll mx = -1e18; for (int k = i; k >= 1; k--) { mx = max(mx, a[k][1]); ll c = (mx - prf[k]) * (mx + prf[k] - 2 * a[k][0]); if (c < 0) continue; dp[j][i] = min(dp[j][i], dp[j - 1][k - 1] + c); } } } for (int i = 2; i + 1 <= m; i++) { assert(dp[i][n] - dp[i - 1][n] <= dp[i + 1][n] - dp[i][n]); } return dp[m][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...