제출 #169086

#제출 시각아이디문제언어결과실행 시간메모리
169086mohammad_kilaniAliens (IOI16_aliens)C++17
0 / 100
115 ms126252 KiB
#include <bits/stdc++.h> #include "aliens.h" using namespace std; const int N = 4010 , K = 4010; vector< pair<int,int> > arr , tmp; long long dp[N][K]; int n , m , k; long long solve(int i,int cur){ if(i == n) return 0; if(cur == k) return (long long)1e18; if(dp[i][cur] != -1) return dp[i][cur]; dp[i][cur] = (long long)1e18; int mx = -1; long long val; for(int j = i ;j < n;j++){ mx = max(mx,arr[j].second); val = (long long)(mx - arr[i].first + 1) * (long long)(mx - arr[i].first + 1); if(j < n - 1){ val -= max(0LL , (long long)(mx - arr[j + 1].first + 1) * (long long)(mx - arr[j + 1].first + 1)); } dp[i][cur] = min(dp[i][cur] , val + solve(j + 1, cur + 1)); } return dp[i][cur]; } 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 = 0 ;i < n;i++){ arr.push_back(make_pair(min(r[i] , c[i]) , -max(r[i] , c[i]))); } sort(arr.begin(),arr.end()); int mx = -1; for(int i = 0 ;i < (int)arr.size();i++){ arr[i].second = -arr[i].second; if(arr[i].second > mx){ tmp.push_back(arr[i]); mx = arr[i].second; } } arr = tmp; n = (int)arr.size(); memset(dp,-1,sizeof(dp)); return solve(0 , 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...