# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
169096 | mohammad_kilani | Aliens (IOI16_aliens) | C++17 | 2052 ms | 126552 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 a[N] , b[N];
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++){
val = (long long)arr[i].first * (long long)arr[i].first;
val += (long long)a[j] * (long long)arr[i].first + b[j];
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){
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();
::n = n;
::m = m;
::k = k;
memset(dp,-1,sizeof(dp));
for(int i = 0 ;i < n;i++){
b[i] = (long long)(arr[i].second + 1) * (long long)(arr[i].second + 1);
if(i < n - 1 && arr[i].second >= arr[i + 1].first)
b[i] -= (long long)(arr[i].second - arr[i + 1].first + 1) * (long long)(arr[i].second - arr[i + 1].first + 1);
a[i] = -2 * (long long)(arr[i].second + 1);
}
return solve(0 , 0);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |