Submission #1023569

#TimeUsernameProblemLanguageResultExecution timeMemory
1023569vjudge1Wish (LMIO19_noras)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; const long double maxd = 1e19; long double sqrt128(__int128 x) { long double l = 0, r = maxd; for (int i=0; i<128; i++) { long double mid = (l + r) / 2; if (mid * mid <= x) { l = mid; } else { r = mid; } } return l; } void solve() { int n; long long r; cin >> n >> r; vector<long long> a(n), b(n), c(n), d(n); for (int i=0; i<n; i++) cin >> a[i] >> b[i] >> c[i] >> d[i]; vector<pair<long long, bool>> evs; for (int i=0; i<n; i++) { // p(t) = (a[i] + t * dx, b[i] + t * dy) // cari t sehingga (a[i] + t * dx)^2 + (b[i] + t * dy)^2 = r^2 // => a[i]^2 + t^2*dx^2 + 2*t*a[i]*dx + b[i]^2 + t^2*dy^2 + 2*t*b[i]*dy = r^2 // => t^2 * (dx^2 + dy^2) + t * (2*a[i]*dx + 2*b[i]*dy) + a[i]^2 + b[i]^2 - r^2 = 0 // => t^2 * A + t * B + C = 0 // pakai rumus akar persamaan kuadrat? __int128 dx = c[i] - a[i], dy = d[i] - b[i]; __int128 A = dx * dx + dy * dy, B = 2 * (a[i] * dx + b[i] * dy), C = a[i] * a[i] + b[i] * b[i] - r * r; __int128 D = B * B - 4 * A * C; if (D >= 0) { long double sd = sqrt128(D); long double t1 = (-B + sd) / (2 * A); long double t2 = (-B - sd) / (2 * A); long long llt1 = ceil(min(t1, t2)); long long llt2 = floor(max(t1, t2)); cout << min(t1, t2) << ' ' << max(t1, t2) << '\n'; cout << llt1 << ' ' << llt2 << '\n'; if (llt1 <= llt2) { evs.emplace_back(llt1, 0); evs.emplace_back(llt2, 1); } } } sort(evs.begin(), evs.end()); int ans = 0, cnt = 0; for (int i=0; i<(int)evs.size(); i++) { auto &[t, rem] = evs[i]; if (t >= 0) ans = max(ans, cnt); if (rem) { cnt--; } else { cnt++; } } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int tcs = 1; // cin >> tcs; while (tcs--) { solve(); } return 0; }
#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...