Submission #476126

#TimeUsernameProblemLanguageResultExecution timeMemory
476126AdamGSAliens (IOI16_aliens)C++14
4 / 100
1 ms204 KiB
#include "aliens.h" #include<bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=1e5+7; const ll INF=1e18+7; vector<pair<ll,ll>>V; ll dp[LIM], lewo[LIM]; ll wynik(int a, int b, ll c) { ll x=abs(V[b].nd-V[a].st)+1; x=x*x+c; if(a) { x+=dp[a-1]; ll y=abs(V[a].st-V[a-1].nd)+1; if(V[a].st<=V[a-1].nd) x-=y*y; } return x; } ll licz(ll c) { int n=V.size(); ll ile=1; dp[0]=wynik(0, 0, c); lewo[0]=0; for(int i=1; i<n; ++i) { ll a=wynik(lewo[i-1], i, c), b=wynik(i, i, c); if(b<a) { lewo[i]=i; dp[i]=b; ++ile; } else { lewo[i]=lewo[i-1]; dp[i]=a; } } return ile; } ll take_photos(int N, int M, int K, vector<int>r, vector<int>c) { ll n=N, m=M, k=K; vector<pair<int,int>>S; rep(i, n) { if(r[i]<=c[i]) S.pb({r[i], -c[i]}); else S.pb({c[i], -r[i]}); } sort(all(S)); int ma=-1; for(auto i : S) { if(ma>=-i.nd) continue; V.pb({i.st, -i.nd}); ma=max(ma, -i.nd); } ll po=0, ko=10000000000000; while(po<ko) { ll sr=(po+ko)/2; if(licz(sr)<=k) ko=sr; else po=sr+1; } licz(po); return dp[V.size()-1]-po*k; }

Compilation message (stderr)

aliens.cpp: In function 'll take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:44:10: warning: unused variable 'm' [-Wunused-variable]
   44 |  ll n=N, m=M, k=K;
      |          ^
#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...