Submission #1084844

#TimeUsernameProblemLanguageResultExecution timeMemory
1084844fyanAliens (IOI16_aliens)C++14
12 / 100
90 ms8360 KiB
#include "bits/stdc++.h" using namespace std; #define i64 int64_t #define all(x) begin(x), end(x) #define sz(x) (int) (x).size() const int MXN=1e3+5, INF=1e9; int N,M,K; array<int,2> arr[MXN]; i64 dp[MXN][MXN]; bool cc1(const array<int,2> &a, const array<int,2> &b) { if (a[0]==b[0]) { return a[1]>b[1]; } return a[0]<b[0]; } bool cc2(const array<int,2> &a, const array<int,2> &b) { return a[1]<b[1]; } i64 take_photos(int n, int m, int k, vector<int> r, vector<int> c) { N = n, M = m, K = min(k,N); for (int i=1; i<=N; i++) { arr[i] = {min(r[i-1],c[i-1]),max(r[i-1],c[i-1])}; } arr[0] = {-INF,-INF}; sort(arr,arr+N+1,cc1); int pv = 0,sub = 0; for (int i=1; i<=N; i++) { if (arr[pv][1] >= arr[i][1]) { sub++; arr[i] = {INF,INF}; } else pv = i; } sort(arr,arr+1+N,cc2); N -= sub; K = min(K,N); memset(dp,0x3f,sizeof(dp)); dp[0][0] = 0; for (int i=1; i<=N; i++) { for (int j=1; j<=K; j++) { for (int p=0; p<i; p++) { i64 area = (arr[i][1]-arr[p+1][0]+1)*(arr[i][1]-arr[p+1][0]+1); i64 dif = 1ll*max(0,arr[p][1]-arr[p+1][0])*max(0,arr[p][1]-arr[p+1][0]); area -= dif; dp[i][j] = min(dp[i][j],dp[p][j-1]+area); } } } return dp[N][K]; } /* signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); vector<int> x = {{0,4,4,4,4}}, y = {{3,4,6,5,6}}; take_photos(5,7,2,x,y); return 0; } */
#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...