제출 #530144

#제출 시각아이디문제언어결과실행 시간메모리
530144NachoLibreAliens (IOI16_aliens)C++17
0 / 100
1 ms292 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define vint vector<int> using namespace std; #ifndef x // #include ".h" #else #endif int n; vint l, r; ll I(int i) { if(r[i] < l[i + 1]) return 0; return powl(r[i] - l[i + 1] + 1, 2); } ll P(array<ll, 3> p, ll x) { return p[0] * x + p[1]; } bool CW(array<ll, 3> a, array<ll, 3> b, array<ll, 3> c) { a[0] = b[0] - a[0]; a[1] = b[1] - a[1]; b[0] = c[0] - b[0]; b[1] = c[1] - b[1]; return (a[0] * b[1] - b[0] * a[1] > 0); } array<ll, 2> dpsol(ll am) { vector<array<ll, 2> > dp(n); dp[0] = {(ll)(am + powl(r[0] - l[0] + 1, 2)), 1}; deque<array<ll, 3> > d; int dg = 0; for(int i = 0; i < n; ++i) { if(i > 0) { ll x = -r[i]; ll c = powl(r[i] + 1, 2); while(dg < sz(d) - 1 && P(d[dg + 1], x) < P(d[dg], x)) dg += 1; dp[i][0] = P(d[dg], x); dp[i][1] = d[dg][2]; } if(i < n - 1) { ll a = 2ll * l[i + 1]; ll b = dp[i][0] + I(i) - 2ll * l[i + 1]; b += powl(l[i + 1], 2); array<ll, 3> x = {a, b, dp[i][1]}; while(sz(d) >= 2 && CW(d[sz(d) - 2], d[sz(d) - 1], x)) { d.pop_back(); if(dg == sz(d)) dg -= 1; } d.push_back(x); } } return dp[n - 1]; } ll take_photos(int N, int m, int k, vint R, vint C) { n = N; vector<int> lg(m, -1); for(int i = 0; i < n; ++i) { array<int, 2> x = {R[i], C[i]}; if(x[0] > x[1]) swap(x[0], x[1]); lg[x[1]] = max(lg[x[1]], x[0]); } vector<array<int, 2> > v; for(int i = 0; i < m; ++i) { if(lg[i] == -1) continue; while(sz(v) && lg[i] <= v.back()[0]) { v.pop_back(); } v.push_back({lg[i], i}); } n = sz(v); l = r = vint(n); for(int i = 0; i < n; ++i) { l[i] = v[i][0]; r[i] = v[i][1]; } ll al = 0, ar = 1e9; while(al < ar) { ll am = al + ar >> 1; if(dpsol(am)[1] > k) al = am + 1; else ar = am; } return dpsol(al)[0]; } #ifdef x int main() { ios::sync_with_stdio(0); cin.tie(0); return 0; } #endif

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

aliens.cpp: In function 'std::array<long long int, 2> dpsol(long long int)':
aliens.cpp:41:7: warning: unused variable 'c' [-Wunused-variable]
   41 |    ll c = powl(r[i] + 1, 2);
      |       ^
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:85:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   85 |   ll am = al + ar >> 1;
      |           ~~~^~~~
#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...