Submission #899026

#TimeUsernameProblemLanguageResultExecution timeMemory
899026WLZMobile (BOI12_mobile)C++17
100 / 100
228 ms104876 KiB
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "debug.hpp" #include "lib/geodeb.h" #else #define debug(...) #define GD_INIT(...) #define GD_POINT(...) #define GD_LAYER(...) #define GD_LINE(...) #define GD_SEGMENT(...) #endif using ld = long double; constexpr ld inf = numeric_limits<long double>::infinity(); constexpr ld eps = 1e-9; // https://github.com/kth-competitive-programming/kactl/blob/main/content/geometry/Point.h template<class T> struct Point { typedef Point P; T x, y; explicit Point(T _x = 0, T _y = 0) : x(_x), y(_y) {} P operator+(P p) const { return P(x + p.x, y + p.y); } P operator-(P p) const { return P(x - p.x, y - p.y); } P operator/(T d) const { return P(x / d, y / d); } T dist2() const { return x*x + y*y; } ld dist() const { return sqrt((ld) dist2()); } P perp() const { return P(-y, x); } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); GD_INIT("geodeb.html"); int n; ld l; cin >> n >> l; vector< Point<int> > p1(n); for (int i = 0; i < n; i++) cin >> p1[i].x >> p1[i].y; int px = (int) -2e9, py = -2e9; vector< Point<ld> > p; for (auto &[x, y] : p1) { if (x == px) py = min(py, abs(y)); else { if (px > (int) -2e9) p.emplace_back(px, py); px = x; py = abs(y); } } p.emplace_back(px, py); n = (int) p.size(); GD_SEGMENT(0, 0, l, 0, "black bold"); for (auto &[x, y] : p) GD_POINT(x, y, "black bold"); vector<ld> ends = {-inf}; vector< Point<ld> > st = {p[0]}; for (int i = 1; i < n; i++) { GD_LAYER(); GD_POINT(p[i].x, p[i].y, "red bold"); while (true) { GD_LAYER(); for (auto &e : ends) GD_POINT(clamp(e, 0.0l, l), 0, "red bold"); auto q = st.back(); GD_SEGMENT(p[i].x, p[i].y, q.x, q.y, "red bold"); auto m = (p[i] + q) / 2; GD_POINT(m.x, m.y, "blue bold"); auto tmp = (q - p[i]).perp() + m; GD_LINE(m.x, m.y, tmp.x, tmp.y, "black bold"); ld k = -m.y / (q.x - p[i].x); ld x = m.x - k * (q.y - p[i].y); GD_POINT(x, 0, "blue bold"); if (x < ends.back()) { st.pop_back(); ends.pop_back(); } else { st.push_back(p[i]); ends.push_back(x); break; } } for (auto &e : ends) GD_POINT(clamp(e, 0.0l, l), 0, "red bold"); } ends.push_back(inf); ld ans = 0.0; for (int i = 0; i < (int) st.size(); i++) { ld a = max(0.0l, ends[i]), b = min(l, ends[i + 1]); if (a < b) { ans = max(ans, (Point<ld>(a, 0) - st[i]).dist()); ans = max(ans, (Point<ld>(b, 0) - st[i]).dist()); } } cout << fixed << setprecision(4) << ans << '\n'; return 0; }

Compilation message (stderr)

mobile.cpp: In function 'int main()':
mobile.cpp:54:16: warning: unused structured binding declaration [-Wunused-variable]
   54 |     for (auto &[x, y] : p) GD_POINT(x, y, "black bold");
      |                ^~~~~~
mobile.cpp:65:24: warning: unused variable 'e' [-Wunused-variable]
   65 |             for (auto &e : ends) GD_POINT(clamp(e, 0.0l, l), 0, "red bold");
      |                        ^
mobile.cpp:71:18: warning: variable 'tmp' set but not used [-Wunused-but-set-variable]
   71 |             auto tmp = (q - p[i]).perp() + m;
      |                  ^~~
mobile.cpp:83:20: warning: unused variable 'e' [-Wunused-variable]
   83 |         for (auto &e : ends) GD_POINT(clamp(e, 0.0l, l), 0, "red bold");
      |                    ^
#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...
#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...
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...