Submission #680489

#TimeUsernameProblemLanguageResultExecution timeMemory
680489ngraceAliens (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); } long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { set<pii> tmp; for(int i=0;i<n;i++){ tmp.insert({min(r[i],c[i]),-max(c[i],r[i])}); } cin.tie(0); 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 h=0; h<=k; h++) opt[h][n+1]=n; v<v<ll>> dp(k+1, v<ll>(n+1, 1e18)); for(int h=0; h<=k; h++) dp[h][0] = 0; for(int h=1; h<=k; h++){ for(int i=n; i>0; i--){ for(int j=opt[h-1][i]; j<=min(i-1, opt[h][i+1]); j++){ ll cost = dp[h-1][j] + C(i,j); if(cost<dp[h][i]){ dp[h][i] = cost; opt[h][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 h=2; h<=k; h++){ comp(1, n, 0, n); dplast = dpcur; } cout<<dplast[n]<<endl; } }

Compilation message (stderr)

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:38:9: error: 'pii' was not declared in this scope; did you mean 'ii'?
   38 |     set<pii> tmp;
      |         ^~~
      |         ii
aliens.cpp:38:12: error: template argument 1 is invalid
   38 |     set<pii> tmp;
      |            ^
aliens.cpp:38:12: error: template argument 2 is invalid
aliens.cpp:38:12: error: template argument 3 is invalid
aliens.cpp:40:13: error: request for member 'insert' in 'tmp', which is of non-class type 'int'
   40 |         tmp.insert({min(r[i],c[i]),-max(c[i],r[i])});
      |             ^~~~~~
aliens.cpp:44:15: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   44 |     for(ii it:tmp){
      |               ^~~
      |               std::begin
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from aliens.cpp:1:
/usr/include/c++/10/valarray:1224:5: note: 'std::begin' declared here
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
aliens.cpp:44:15: error: 'end' was not declared in this scope; did you mean 'std::end'?
   44 |     for(ii it:tmp){
      |               ^~~
      |               std::end
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from aliens.cpp:1:
/usr/include/c++/10/valarray:1244:5: note: 'std::end' declared here
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
aliens.cpp:78:1: warning: no return statement in function returning non-void [-Wreturn-type]
   78 | }
      | ^