Submission #617402

#TimeUsernameProblemLanguageResultExecution timeMemory
617402HazemAliens (IOI16_aliens)C++14
0 / 100
2089 ms212 KiB
#include <bits/stdc++.h> #define F first #define S second #define LL long long using namespace std; const int N = 4e3+10; const LL LINF = 1e18; pair<int,int>p[N]; LL dp[N][N]; bool cmp(pair<int,int>p1,pair<int,int>p2){ if(p1.F!=p2.F) return p1.F<p2.F; return p1.S>p2.S; } 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++){ if(r[i]>c[i]) swap(r[i],c[i]); p[i] = {c[i],r[i]}; } sort(p,p+n); vector<pair<int,int>>vec; int mn = 1e9+10; for(int i=n-1;i>=0;i--){ if(mn<=p[i].S) continue; vec.push_back(p[i]); mn = min(mn,p[i].S); } vec.push_back({-1,-1}); reverse(vec.begin(),vec.end()); for(int j=1;j<=k;j++) dp[0][j] = LINF; int last = 1; for(int j=1;j<=k;j++){ for(int i=1;i<vec.size();i++){ dp[i][0] = LINF; dp[i][j] = LINF; if(last>1) last--; for(;last<=i;){ LL d = (vec[i].F-vec[last].S+1),d1 = max(0,vec[last-1].F-vec[last].S+1); d *= d; d1 *= d1; if(dp[last-1][j-1]+d-d1<dp[i][j]) dp[i][j] = dp[last-1][j-1]+d-d1,last++; } } } LL ans = LINF; for(int i=1;i<=k;i++) ans = min(ans,dp[vec.size()-1][i]); return ans; }

Compilation message (stderr)

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for(int i=1;i<vec.size();i++){
      |                     ~^~~~~~~~~~~
#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...