제출 #666882

#제출 시각아이디문제언어결과실행 시간메모리
666882LoboAliens (IOI16_aliens)C++17
100 / 100
192 ms6760 KiB
#include<bits/stdc++.h> #include "aliens.h" using namespace std; #define int long long #define dbl long double #define fr first #define sc second #define mp make_pair #define pb push_back #define all(x) x.begin(),x.end() const int inf = 1e18+10; int n; vector<pair<int,int>> pts; deque<pair<pair<int,int>,int>> cht; dbl intx(int a1, int b1, int a2, int b2) { // x*a1 + b1 = x*a2 + b2 // x*(a1-a2) = b2-b1 // x = (b2-b1)/(a1-a2) return ((dbl) b2-b1)/((dbl) a1-a2); } int func(int a, int b, int x) { return a*x+b; } void chtclear() { cht.clear(); } void chtadd(int a, int b, int k) { while(cht.size() >= 2 && (intx(a,b,cht[1].fr.fr,cht[1].fr.sc) > intx(cht[0].fr.fr,cht[0].fr.sc,cht[1].fr.fr,cht[1].fr.sc) || (intx(a,b,cht[1].fr.fr,cht[1].fr.sc) == intx(cht[0].fr.fr,cht[0].fr.sc,cht[1].fr.fr,cht[1].fr.sc) && k <= cht[0].sc))) { cht.pop_front(); } cht.push_front(mp(mp(a,b),k)); } pair<int,int> chtqry(int x) { while(cht.size() >= 2 && (func(cht.back().fr.fr,cht.back().fr.sc,x) > func(cht[cht.size()-2].fr.fr,cht[cht.size()-2].fr.sc,x) || (func(cht.back().fr.fr,cht.back().fr.sc,x) == func(cht[cht.size()-2].fr.fr,cht[cht.size()-2].fr.sc,x) && cht[cht.size()-2].sc <= cht.back().sc))) { cht.pop_back(); } return mp(func(cht.back().fr.fr,cht.back().fr.sc,x),cht.back().sc); } pair<int,int> sol(int p) { pair<int,int> dp[n]; chtclear(); for(int i = 0; i < n; i++) { int xi = pts[i].fr; int yi = pts[i].sc; if(i == 0) { int xj = pts[i].fr; int yj = pts[i].sc; chtadd(yj,yj*yj - 2*yj,0); } else { int j = i; int xj = pts[i].fr; int yj = pts[i].sc; int xj1 = pts[i-1].fr; int yj1 = pts[i-1].sc; chtadd(yj,(dp[j-1].fr + yj*yj - 2*yj - max((int)0,xj1-yj+1)*max((int) 0,xj1-yj+1)),dp[j-1].sc); } pair<int,int> anshere = chtqry(-2*xi); dp[i] = mp(anshere.fr + (xi*xi + 2*xi + 1) + p, anshere.sc+1); } return dp[n-1]; } int take_photos(int32_t N, int32_t m, int32_t k, vector<int32_t> rw, vector<int32_t> cl) { for(int i = 0; i < N; i++) { int x = cl[i]; int y = rw[i]; if(x < y) swap(x,y); pts.pb(mp(x,-y)); } sort(all(pts)); stack<pair<int,int>> prt; for(auto X : pts) { int x = X.fr; int y = -X.sc; while(prt.size() && prt.top().sc >= y) prt.pop(); prt.push(mp(x,y)); } pts.clear(); while(prt.size()) { pts.pb(prt.top()); prt.pop(); } sort(all(pts)); n = pts.size(); int l = 0; int r = (int) m*m; int ans = -1; while(l <= r) { int mid = (l+r)>>1; auto dp = sol(mid); if(dp.sc > k) { l = mid+1; } else { ans = dp.fr-k*mid; r = mid-1; } } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

aliens.cpp: In function 'std::pair<long long int, long long int> sol(long long int)':
aliens.cpp:54:17: warning: unused variable 'xj' [-Wunused-variable]
   54 |             int xj = pts[i].fr;
      |                 ^~
aliens.cpp:60:17: warning: unused variable 'xj' [-Wunused-variable]
   60 |             int xj = pts[i].fr;
      |                 ^~
aliens.cpp:63:17: warning: unused variable 'yj1' [-Wunused-variable]
   63 |             int yj1 = pts[i-1].sc;
      |                 ^~~
aliens.cpp:51:13: warning: unused variable 'yi' [-Wunused-variable]
   51 |         int yi = pts[i].sc;
      |             ^~
#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...