제출 #200520

#제출 시각아이디문제언어결과실행 시간메모리
200520oscarsierra12Aliens (IOI16_aliens)C++14
4 / 100
8 ms4344 KiB
#include "aliens.h" #include <bits/stdc++.h> using namespace std ; #define ff first #define ss second typedef long long ll ; typedef pair<ll,ll> pll ; const int M = 1e6+2 ; const int N = 1e5+2 ; int mxCoor[ M ] ; vector <pll> points ; int sz ; pll dp [N]; long double Lowpend, Hgpend, Midpend ; int last ; struct info { ll m, b, ind ; info ( ll m1, ll b1, ll ind1 ) { m = m1 ; b = b1 ; ind = ind1 ; } }; vector <info> convex ; long double comm ( info A, info B ) { return (1.0*B.b - A.b) / (A.m - B.m) ; } void add ( info cur ) { while ( 1 ) { if ( convex.size() < 2 ) { convex.push_back ( cur ) ; break ; } info tp = convex.back() ; convex.pop_back() ; info scn = convex.back() ; if ( comm ( cur, scn ) > comm ( scn, tp ) ) { convex.push_back ( tp ) ; convex.push_back ( cur ) ; break ; } } } info query ( int p ) { int lw = 0, hg = convex.size() ; --hg ; while ( lw < hg ) { int mid = (lw+hg)/2 ; long double inter = comm(convex[mid], convex[mid+1]) ; // cout << mid << ' ' << inter << ' '<< p << '\n' ; if ( inter == p ) return convex[mid] ; if ( inter < p ) lw = mid+1 ; else hg = mid ; } return convex[lw] ; } ll intersect ( int k ) { ll inters = points[k].ss - points[k+1].ff + 1; if ( inters < 0 ) inters = 0 ; inters *= inters ; return inters ; } long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { memset ( mxCoor, -1, sizeof mxCoor ) ; for ( int i = 0 ; i < n ; ++i ) { if ( c[i] >= r[i] ) mxCoor [r[i]] = max ( mxCoor [r[i]], c[i] ) ; else mxCoor [c[i]] = max ( mxCoor [c[i]], r[i] ) ; } int mx = -1 ; for ( int i = 0 ; i < m ; ++i ) { if ( mxCoor[i] <= mx ) continue ; mx = mxCoor[i] ; points.push_back({i,mx}) ; } sz = points.size() ; last = mx+1 ; Lowpend = 0, Hgpend = 1ll*last*last ; while ( fabs(Lowpend-Hgpend) > 1e-5 ) { convex.clear() ; Midpend = (Lowpend+Hgpend)/2 ; dp[sz-1] = {(points[sz-1].ss-points[sz-1].ff+1) * (points[sz-1].ss-points[sz-1].ff+1),1} ; // cout << dp[sz-1].ff << '\n' ; if ( sz > 1 ) { info *x = new info( 1ll*points[sz-2].ss, 1ll*dp[sz-1].ff - intersect (sz-2) + points[sz-2].ss * points[sz-2].ss, 1ll*sz-1 ) ; add(*x) ; } for ( int i = sz-2 ; i >= 0 ; --i ) { info opt = query(-2*(points[i].ff-1)) ; //cout << opt.ind << ' ' << opt.m << ' ' << opt.b << '\n' ; dp[i].ff = (points[i].ff-1)*(points[i].ff-1) - 2*(points[i].ff-1)*(opt.m) + opt.b ; dp[i].ss = dp[opt.ind].ss + 1 ; if ( (last-points[i].ff)*(last-points[i].ff) - dp[i].ff < Midpend ) dp[i] = {(last-points[i].ff)*(last-points[i].ff), 1} ; // cout << i << ' ' << dp[i].ff << ' ' << Midpend << '\n' ; if ( i ) { info *x = new info( 1ll*points[i-1].ss, 1ll*dp[i].ff - intersect (i-1) + points[i-1].ss * points[i-1].ss, 1ll*i ) ; // cout << i << ' ' << points[i-1].ss << ' ' << dp[i].ff << ' ' << intersect (i-1) + points[i-1].ss * points[i-1].ss << "Adding\n" ; add(*x) ; } } if ( dp[0].ss <= k ) Hgpend = Midpend; else Lowpend = Midpend ; } // cout << Hgpend << '\n' ; return dp[0].ff; } /* 4 10 2 0 0 1 1 8 8 9 9 */
#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...