Submission #375609

#TimeUsernameProblemLanguageResultExecution timeMemory
375609mode149256Wish (LMIO19_noras)C++17
100 / 100
203 ms15120 KiB
/*input 2 1 -3 -2 -1 -1 -2 2 -1 1 */ #include <bits/stdc++.h> using namespace std; namespace my_template { typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<vl> vll; typedef vector<pi> vpi; typedef vector<vpi> vpii; typedef vector<pl> vpl; typedef vector<cd> vcd; typedef vector<pd> vpd; typedef vector<bool> vb; typedef vector<vb> vbb; typedef std::string str; typedef std::vector<str> vs; #define x first #define y second #define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n" const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L; template<typename T> pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); } template<typename T> pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); } template<typename T> T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); } template<typename T> T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); } template<typename T> void print(vector<T> vec, string name = "") { cout << name; for (auto u : vec) cout << u << ' '; cout << '\n'; } } using namespace my_template; const int MOD = 200000007; const ll INF = 1e12; const int MX = 100101; struct beam { pl prad; pl dxy; }; int N; ll R; ll dis(pl a, pl b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } pl getnth(ll n, pl a, pl dxy) { return {a.x + dxy.x * n, a.y + dxy.y * n}; } pl getnth(ll n, beam b) { return getnth(n, b.prad, b.dxy); } ll getINF(beam b) { return (MOD) / max(abs(b.dxy.x), abs(b.dxy.y)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> R; pl og = {0, 0}; vector<beam> sk(N); for (int i = 0; i < N; ++i) { ll a, b, c, d; cin >> a >> b >> c >> d; sk[i] = beam{{a, b}, {c - a, d - b}}; } auto closest = [&](beam b) -> ll { ll l = 0; ll h = getINF(b); // printf("%lld %lld, %lld %lld, h = %lld\n", b.prad.x, b.prad.y, b.dxy.x, b.dxy.y, h); ll m; while (h - l > 6) { m = (l + h) / 2; pl n1 = getnth(m, b); pl n2 = getnth(m + 1, b); ll d1 = dis(n1, og); ll d2 = dis(n2, og); if (d1 == d2) { return m; } else if (d1 < d2) { h = m; } else { l = m; } } pl ret = getnth(l, b); ll n = l; ll c = dis(ret, og); for (ll i = l + 1; i <= h; ++i) { pl nl = getnth(i, b); ll nc = dis(nl, og); if (nc < c) { c = nc; ret = nl; n = i; } } return n; }; auto pirmas = [&](beam b, ll best_dis) -> ll { ll l = 0; ll h = best_dis; ll m; while (l < h) { m = (l + h) / 2; pl n1 = getnth(m, b); ll d1 = dis(n1, og); if (d1 <= R * R) { h = m; } else { l = m + 1; } } return l; }; auto pask = [&](beam b, ll best_dis) -> ll { ll l = best_dis; ll h = getINF(b); ll m; while (l < h) { m = (l + h + 1) / 2; pl n1 = getnth(m, b); ll d1 = dis(n1, og); if (d1 <= R * R) { l = m; } else { h = m - 1; } } return l; }; vector<pl> kas; for (auto b : sk) { ll ind = closest(b); // printf("%lld %lld, ind = %lld\n", b.prad.x, b.prad.y, ind); if (dis(getnth(ind, b), og) > R * R) continue; ll from = pirmas(b, ind); ll to = pask(b, ind); // printf("%lld %lld, %lld %lld, from = %lld, to = %lld\n", b.prad.x, b.prad.y, b.dxy.x, b.dxy.y, from, to); assert(from <= to); kas.emplace_back(from, 1); kas.emplace_back(to + 1, -1); } sort(kas.begin(), kas.end()); ll ats = 0; ll curr = 0; int j = 0; while (j < (int)kas.size()) { ll dabar = kas[j].x; while (j < (int)kas.size() and kas[j].x == dabar) { curr += kas[j].y; j++; } ats = max(ats, curr); } printf("%lld\n", ats); } /* Look for: * special cases (n=1?) * overflow (ll vs int?) * the exact constraints (multiple sets are too slow for n=10^6 :( ) * array bounds */
#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...