제출 #197415

#제출 시각아이디문제언어결과실행 시간메모리
197415abacabaAliens (IOI16_aliens)C++14
4 / 100
35 ms4728 KiB
#include <iostream> #include <string> #include <unordered_map> #include <unordered_set> #include <cstring> #include <chrono> #include <vector> #include <map> #include <random> #include <set> #include <algorithm> #include <math.h> #include <cstdio> #include <stdio.h> #include <queue> #include <bitset> #include <cstdlib> #include <deque> #include <cassert> #include <stack> using namespace std; #define mp make_pair #define f first #define se second #define pb push_back #define ppb pop_back #define ll long long #define ull unsigned long long #define cntbit(x) __builtin_popcount(x) #define endl '\n' #define uset unordered_set #define umap unordered_map #define all(x) x.begin(), x.end() #define pii pair<int, int> #define ld long double #define pll pair<long long, long long> const int mod = 1e9 + 7; const ld inf = 1e18; const int N = 1e5 + 15; pair <ld, int> dp[N]; int l[N], r[N]; int ord[N]; vector <pii> tmp; ll val[N]; inline ll sq(ll x) { return x * x; } inline void Min(pair <ld, int> &a, pair <ld, int> b) { a = min(a, b); } struct line { ld k, b; int t; line(ld k, ld b, int t) : k(k), b(b), t(t) { } inline pair <ld, int> get(int x) { return mp(k * x + b, t + 1); } }; vector <line> hull; int ptr; inline bool bad(line a, line b, line c) { return (a.b - c.b) * (c.k - b.k) >= (c.k - a.k) * (b.b - c.b); } inline void add(line nw) { while(hull.size() > 1 && bad(hull[hull.size() - 2], hull.back(), nw)) hull.ppb(); hull.pb(nw); } inline pair <ld, int> get(int x) { ptr = min(ptr, (int)hull.size() - 1); while(ptr + 1 < hull.size() && hull[ptr].get(x) >= hull[ptr + 1].get(x)) ++ptr; return hull[ptr].get(x); } inline int check(ld C, int n) { hull.clear(); ptr = 0; for(int i = 1; i < N; ++i) dp[i] = mp(inf, 0); dp[0] = mp(0, 0); for(int i = 1; i <= n; ++i) { add(*new line(-2 * l[i], sq(l[i]) + dp[i-1].f - val[i] + C, dp[i-1].se)); pair <ld, int> valnw = get(r[i] + 1); valnw.f += sq(r[i] + 1); Min(dp[i], valnw); } return dp[n].se; } ll take_photos(int n, int m, int k, std::vector<int> row, std::vector<int> col) { for(int i = 0; i < n; ++i) { l[i+1] = min(row[i], col[i]) + 1; r[i+1] = max(row[i], col[i]) + 1; ord[i+1] = i+1; } sort(ord + 1, ord + 1 + n, [&](int x, int y) { return mp(l[x], -r[x]) < mp(l[y], -r[y]); }); for(int i = 1; i <= n; ++i) if(tmp.empty() || !(tmp.back().f <= l[ord[i]] && tmp.back().se >= r[ord[i]])) tmp.pb(mp(l[ord[i]], r[ord[i]])); n = tmp.size(); for(int i = 1; i <= n; ++i) { l[i] = tmp[i-1].f, r[i] = tmp[i-1].se; val[i] = sq(max(0, r[i-1] - l[i] + 1)); } ld l = 0, r = (ll)m * m, res = 0; for(int iter = 0; iter < 50; ++iter) { ld mid = (l + r) / 2; int val = check(mid, n); if(val <= k) { r = mid; res = mid; } else l = mid; } check(res, n); return (dp[n].f - res * dp[n].se); }

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

aliens.cpp: In function 'std::pair<long double, int> get(int)':
aliens.cpp:80:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(ptr + 1 < hull.size() && hull[ptr].get(x) >= hull[ptr + 1].get(x))
           ~~~~~~~~^~~~~~~~~~~~~
#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...