제출 #169131

#제출 시각아이디문제언어결과실행 시간메모리
169131mohammad_kilaniAliens (IOI16_aliens)C++17
25 / 100
10 ms504 KiB
#include <bits/stdc++.h> #include "aliens.h" using namespace std; const int N = 1000010 , K = 2; vector< pair<long long,long long> > arr , tmp; long long dp[N][K]; int n , m , k; long long a[N] , b[N] , c[N] , tmpb[N]; long long tmp1 , g; inline long long get(long long a1,long long b1,long long a2,long long b2){ assert(a1 > a2); tmp1 = (b2 - b1) / (a1 - a2) - ((((b2 - b2) < 0) ^ ((a1 - a2) < 0) && (abs(b2 - b1) % abs(b1 - a2) != 0)) ? 1 : 0); return tmp1; } 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()); long long 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; 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); c[i] = (long long)arr[i].first * (long long)arr[i].first; } for(int i = 0 ;i < n;i++){ dp[i][k & 1] = (long long)3e18; } pair<long long,int> tmp; for(int j = k - 1;j >= 0;j--){ deque < pair<long long,int> > q; for(int i = n - 1;i >= 0 ;i--){ tmpb[i] = dp[i + 1][((j & 1) ^ 1)] + b[i]; dp[i][(j & 1)] = c[i] + (long long)a[i] * (long long)arr[i].first + tmpb[i]; while((int)q.size() > 1){ tmp = q.back(); q.pop_back(); if(q.back().first < (long long)arr[i].first){ q.push_back(tmp); break; } } if((int)q.size() > 0){ tmp = q.back(); dp[i][(j & 1)] = min(dp[i][(j & 1)] , (long long)c[i] + (long long)a[tmp.second] * (long long)arr[i].first + tmpb[tmp.second]); } while((int)q.size() > 0){ g = get(a[i] , tmpb[i] , a[q.front().second] , tmpb[q.front().second]); if(g >= q.front().first){ q.pop_front(); continue; } break; } if((int)q.size() == 0) g = (long long)3e18; else g = get(a[i] , tmpb[i] , a[q.front().second] , tmpb[q.front().second]); q.push_front(make_pair(g , i)); } } return dp[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...