답안 #1023563

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1023563 2024-07-15T02:32:31 Z vjudge1 Wish (LMIO19_noras) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

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_t dx = c[i] - a[i], dy = d[i] - b[i];
		__int128_t 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_t D = B * B - 4 * A * C;
		if (D >= 0) {
			long double sd = sqrt(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));
			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;
}

Compilation message

noras.cpp: In function 'void solve()':
noras.cpp:23:27: error: call of overloaded 'sqrt(__int128&)' is ambiguous
   23 |    long double sd = sqrt(D);
      |                           ^
In file included from /usr/include/features.h:461,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/c++config.h:518,
                 from /usr/include/c++/10/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from noras.cpp:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:143:1: note: candidate: 'double sqrt(double)'
  143 | __MATHCALL (sqrt,, (_Mdouble_ __x));
      | ^~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from noras.cpp:1:
/usr/include/c++/10/cmath:467:3: note: candidate: 'constexpr long double std::sqrt(long double)'
  467 |   sqrt(long double __x)
      |   ^~~~
/usr/include/c++/10/cmath:463:3: note: candidate: 'constexpr float std::sqrt(float)'
  463 |   sqrt(float __x)
      |   ^~~~