Submission #43034

#TimeUsernameProblemLanguageResultExecution timeMemory
43034nonocutAliens (IOI16_aliens)C++14
4 / 100
9 ms624 KiB
#include "aliens.h" #include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<ll,ll> #define X first #define Y second const int maxn = 1e3 + 5; struct line { ll m,c,val; line(ll _m = 0, ll _c = 0, ll _val = 0) { m = _m; c = _c; val = _val; } }; int n,m,k,sz; pii p[maxn]; pii dp[maxn]; line cht[maxn]; ll getpow(ll x) { return x*x; } double cut(int x, int y) { if(x==0 || y==0) return -2e16; return (double)(cht[y].c-cht[x].c)/(cht[x].m-cht[y].m); } void solve(ll cost) { int len = 0; // printf("solve %lld\n",cost); cht[++len] = line(-2*p[0].X,getpow(p[0].X),1); for(int x=0;x<sz;x++) { int pos = 1; for(int i=1;i<=len;i++) { if(cht[i].m*p[x].Y+cht[i].c < cht[pos].m*p[x].Y+cht[pos].c) pos = i; else if(cht[i].m*p[x].Y+cht[i].c == cht[pos].m*p[x].Y+cht[pos].c && cht[i].val<cht[pos].val) pos = i; } dp[x] = {cht[pos].m*p[x].Y + cht[pos].c + getpow(p[x].Y) + cost, cht[pos].val}; //update line t = line(-2*p[x+1].X, dp[x].X - getpow(max(0LL,p[x].Y-p[x+1].X)) + getpow(p[x+1].X), dp[x].Y+1); cht[++len] = t; // printf("dp %d = {%lld, %lld}\n",x,dp[x].X,dp[x].Y); } } bool cmp(pii x, pii y) { if(x.X!=y.X) return x.X<y.X; return x.Y>y.Y; } long long take_photos(int N, int M, int K, std::vector<int> R, std::vector<int> C) { n = N; m = M; k = K; //prep for(int i=0;i<n;i++) { p[i] = {R[i],C[i]}; if(p[i].X>p[i].Y) swap(p[i].X,p[i].Y); p[i].Y++; } sort(p,p+n,cmp); ll cur = -1; for(int i=0;i<n;i++) { if(p[i].Y<=cur) continue; p[sz++] = p[i]; cur = p[i].Y; } //solve ll l = 0, r = 1e13, mid, pos; ll ans; while(l<r) { mid = (l+r)/2; solve(mid); if(dp[sz-1].Y<=k) pos = mid, r = mid-1; else l = mid+1; } solve(pos); return dp[sz-1].X - pos*dp[sz-1].Y; }

Compilation message (stderr)

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:73:5: warning: unused variable 'ans' [-Wunused-variable]
  ll ans;
     ^
aliens.cpp:80:12: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
  solve(pos);
            ^
#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...