제출 #44378

#제출 시각아이디문제언어결과실행 시간메모리
44378szawinisAliens (IOI16_aliens)C++17
0 / 100
2 ms688 KiB
#include "aliens.h" #include <bits/stdc++.h> using ll = long long; using namespace std; inline ll square(ll x) { return x*x; } void tidy_up(int &n, vector<int> &l, vector<int> &r) { for(int i = 0; i < n; i++) if(l[i] > r[i]) swap(l[i], r[i]); vector<int> id(n); iota(id.begin(), id.end(), 0); sort(id.begin(), id.end(), [l, r] (int i, int j) { return make_pair(r[i], -l[i]) < make_pair(r[j], -l[j]); }); vector<int> tmp; tmp.push_back(-1); tmp.push_back(id[0]); for(int i = 1; i < n; i++) { while(tmp.size() > 1 && l[tmp.back()] >= l[id[i]]) tmp.pop_back(); tmp.push_back(id[i]); } n = tmp.size() - 1; id = tmp; for(int i = 1; i <= n; i++) tmp[i] = r[id[i]]; r = tmp; for(int i = 1; i <= n; i++) tmp[i] = l[id[i]]; l = tmp; } struct cht { struct line { ll m, c; line(ll m, ll c): m(m), c(c) {}; ll getVal(ll x) { return m*x + c; } }; vector<line> f; bool bad(line l1, line l2, line l3) { // m1 > m2 > m3 return (double) (l1.c-l3.c)*(l2.m-l1.m) <= (double) (l1.c-l2.c)*(l3.m-l1.m); } void insert(ll m, ll c) { line l = line(m, c); while(f.size() >= 2 && bad(f[f.size()-2], f[f.size()-1], l)) f.pop_back(); f.push_back(l); } ll query(ll x) { static int idx = 0; while(idx+1 < f.size() && f[idx+1].getVal(x) < f[idx].getVal(x)) ++idx; return f[idx].getVal(x); } void clear() { f.clear(); } } hull; vector<vector<ll> > dp; ll take_photos(int n, int m, int k, vector<int> l, vector<int> r) { tidy_up(n, l, r); dp = vector<vector<ll> >(k+1, vector<ll>(n+1, -1)); hull.insert(-2*(l[1]-1), square(l[1]-1)); for(int j = 1; j <= k; j++) { dp[j][0] = 0; for(int i = 1; i <= n; i++) { dp[j][i] = hull.query(r[i]) + square(r[i]); } hull.clear(); for(int i = 1; i < n; i++) { hull.insert(-2*(l[i+1]-1), square(l[i+1]-1) + dp[j][i] - square(max(0, r[i] - l[i+1] + 1))); } } return dp[k][n]; }

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

aliens.cpp: In member function 'll cht::query(ll)':
aliens.cpp:47:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(idx+1 < f.size() && f[idx+1].getVal(x) < f[idx].getVal(x)) ++idx;
         ~~~~~~^~~~~~~~~~
#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...