Submission #638413

#TimeUsernameProblemLanguageResultExecution timeMemory
638413LeticiaFCSWish (LMIO19_noras)C++17
93 / 100
154 ms14664 KiB
#include "bits/stdc++.h" #define st first #define nd second using lint = int64_t; constexpr int MOD = int(1e9) + 7; constexpr int INF = 0x3f3f3f3f; constexpr int NINF = 0xcfcfcfcf; constexpr lint LINF = 0x3f3f3f3f3f3f3f3f; const long double PI = acosl(-1.0); // Returns -1 if a < b, 0 if a = b and 1 if a > b. int cmp_double(double a, double b = 0, double eps = 1e-9) { return a + eps > b ? b + eps > a ? 0 : 1 : -1; } using namespace std; using ld = long double; bool inCircle(lint x, lint y, lint dx, lint dy, lint r, lint t){ return ( (x + dx*t)*(x + dx*t) + (y + dy*t)*(y + dy*t) ) <= r*r; } pair<bool, lint> firstInCircle(lint x, lint y, lint dx, lint dy, lint r, ld dbt){ lint s = lint(dbt) - 3; lint e = s + 6; for(lint t = s; t<=e; t++) if(inCircle(x,y,dx,dy,r, t)) return {true,t}; return {false, -1}; } pair<bool, lint> lastInCircle(lint x, lint y, lint dx, lint dy, lint r, ld dbt){ lint s = lint(dbt) + 3; lint e = s - 6; for(lint t = s; t>=e; t--) if(inCircle(x,y,dx,dy,r, t)) return {true,t}; return {false, -1}; } vector<lint> intersection(lint x, lint y, lint dx, lint dy, lint r){ vector<lint> answer; lint a = (dx*dx + dy*dy); lint b = (2ll*x*dx + 2ll*y*dy); lint c = -(r*r - x*x - y*y); lint delta = b*b - 4ll*a*c; if(delta < 0) return answer; if(delta == 0){ ld t = ld(-b) / ld(2*a); auto left = firstInCircle(x,y,dx,dy,r,t); if(!left.first) return {}; auto right = lastInCircle(x,y,dx,dy,r,t); if(!right.first) return {}; answer = {left.second, right.second}; }else{ auto left = firstInCircle(x,y,dx,dy,r, ( ld(-b) - sqrtl((ld)delta))/ ld(2*a) ); if(!left.first) return {}; auto right = lastInCircle(x,y,dx,dy,r, (ld(-b) + sqrtl((ld)delta))/ ld(2*a) ); if(!right.first) return {}; answer = {left.second, right.second}; } if(answer[0] < 0) answer[0] = 0; if(answer[0] > answer[1]) answer = {}; else if(answer.back() < 0) answer = {}; return answer; } vector<lint> comprTime; int main() { cin.tie(nullptr)->sync_with_stdio(false); comprTime = {-1}; int n; lint r; cin>>n>>r; vector<vector<lint>> stars; for(int i=0; i<n; i++){ lint x1, y1, x2, y2; cin>>x1>>y1>>x2>>y2; auto v = intersection(x1, y1, x2-x1, y2-y1, r); if(!v.empty()){ stars.push_back(v); comprTime.push_back(v[0]); comprTime.push_back(v[1]); } } sort(comprTime.begin(), comprTime.end()); comprTime.resize(distance( comprTime.begin(), unique(comprTime.begin(), comprTime.end()) )); comprTime.push_back(comprTime.back()+1); vector<lint> pref(comprTime.size()); for(auto star : stars){ int l = lower_bound(comprTime.begin(),comprTime.end(), star[0]) - comprTime.begin(); int r = upper_bound(comprTime.begin(),comprTime.end(), star[1]) - comprTime.begin(); pref[l]++; pref[r]--; } for(int i=1; i<int(comprTime.size()); i++) pref[i] += pref[i-1]; cout<<*max_element(pref.begin(), pref.end())<<"\n"; return 0; } /* [ ]Leu o problema certo??? [ ]Ver se precisa de long long [ ]Viu o limite dos fors (é n? é m?) [ ]Tamanho do vetor, será que é 2e5 em vez de 1e5?? [ ]Testar sample [ ]Testar casos de borda [ ]1LL no 1LL << i [ ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?) */
#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...