Submission #680488

#TimeUsernameProblemLanguageResultExecution timeMemory
680488ngraceAliens (IOI16_aliens)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define v vector #define ll long long #define ii pair<long long,long long> #define fi first #define se second v<ii> ph; ll C(int i, int j){ // i>j, j is exclusive. ll len = ph[i].se - ph[j+1].fi + 1; ll intersect = max(0LL, ph[j].se - ph[j+1].fi + 1); return len*len - intersect*intersect; } v<ll> dplast, dpcur; void comp(int l, int r, int optl, int optr){ if(l>r) return; int m=(l+r)/2; dpcur[m] = 1e18; int opt; for(int i=optl; i<=min(m-1, optr); i++){ ll cur = dplast[i] + C(m,i); if(cur<dpcur[m]){ dpcur[m]=cur; opt=i; } } comp(l,m-1,optl,opt); comp(m+1,r,opt,optr); } int main(){ cin.tie(0); iostream::sync_with_stdio(0); ll n,m,K; cin>>n>>m>>K;//n points, mxm grid, k photo's allowed set<ii> tmp; //min photo needed per point represented as min(a,b), max(a,b) points on diagonal. for(int i=0; i<n; i++){ int a,b; cin>>a>>b; tmp.insert({min(a,b),-max(a,b)}); } ph.push_back({-1,-1}); for(ii it:tmp){ if(ph.back().se < -it.se) ph.push_back({it.fi, -it.se}); } n=ph.size()-1; if(n<=4000){//knuths v<v<int>> opt(K+1, v<int>(n+2, 0)); for(int k=0; k<=K; k++) opt[k][n+1]=n; v<v<ll>> dp(K+1, v<ll>(n+1, 1e18)); for(int k=0; k<=K; k++) dp[k][0] = 0; for(int k=1; k<=K; k++){ for(int i=n; i>0; i--){ for(int j=opt[k-1][i]; j<=min(i-1, opt[k][i+1]); j++){ ll cost = dp[k-1][j] + C(i,j); if(cost<dp[k][i]){ dp[k][i] = cost; opt[k][i]=j; } } } } cout<<dp[K][n]<<endl; } else{//d&c dplast = v<ll>(n+2,0); dpcur = v<ll>(n+2,0); for(int i=1; i<=n; i++) dplast[i] = C(i,0); for(int k=2; k<=K; k++){ comp(1, n, 0, n); dplast = dpcur; } cout<<dplast[n]<<endl; } }

Compilation message (stderr)

aliens.cpp: In function 'void comp(int, int, int, int)':
aliens.cpp:31:9: warning: 'opt' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |     comp(l,m-1,optl,opt);
      |     ~~~~^~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cc9r69om.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cct1Odvo.o:aliens.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc9r69om.o: in function `main':
grader.cpp:(.text.startup+0xf0): undefined reference to `take_photos(int, int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status