Submission #376010

# Submission time Handle Problem Language Result Execution time Memory
376010 2021-03-10T16:25:48 Z Aldas25 Wish (LMIO19_noras) C++14
100 / 100
749 ms 15596 KB
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 500100, MAXK = 23;
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ld PI = asin(1) * 2;

void setIO () {
    FAST_IO;
}

void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

int n;
ll r;
ll a[MAXN], b[MAXN], c[MAXN], d[MAXN];
ll dx[MAXN], dy[MAXN];

pair<ld, ld> getPos (int i, ld t) {
    ld x = ((ld)a[i]) + ((ld)dx[i]) * t;
    ld y = ((ld)b[i]) + ((ld)dy[i]) * t;
    return {x,y};
}

ld getOptTime (int i) {
    ld le = 0.0, ri = 1e8+1;

    while (ri-le > 1e-2) {
        ld mid1 = le + (ri-le)/3;
        ld mid2 = ri - (ri-le)/3;

        auto pos1 = getPos(i, mid1);
        auto pos2 = getPos(i, mid2);

        if (pos1.f < -1e9 || pos1.f > 1e9 || pos1.s < -1e9 || pos1.s > 1e9)
            ri = mid1;
        else if (pos2.f < -1e9 || pos2.f > 1e9 || pos2.s < -1e9 || pos2.s > 1e9)
            ri = mid2;
        else {
            ld d1 = pos1.f * pos1.f + pos1.s * pos1.s;
            ld d2 = pos2.f * pos2.f + pos2.s * pos2.s;
            if (d1 < d2) ri = mid2;
            else le = mid1;
        }
    }

    return le;
}

bool canReach (int i, ll t) {
    if (t < 0) return false;
    ll x = a[i] + dx[i] * t;
    ll y = b[i] + dy[i] * t;

    if (x < -r || x > r || y < -r || y > r)
        return false;

    ll d = x*x + y*y;
    return d <= r*r;
}

ll getFrBounds (int i, ll t) {
    ll le = 0;
    ll ri;
    if (canReach(i, t+1)) ri = t+1;
    else if (canReach(i, t)) ri = t;
    else if (canReach(i, t-1)) ri = t-1;
    else return -1;

    while (le < ri) {
        ll mid = (le+ri)/2;
        if (canReach(i, mid)) ri = mid;
        else le = mid+1;
    }

    return le;
}

ll getToBounds (int i, ll t) {
    ll ri = 1e8+1;
    ll le;
    if (canReach(i, t-1)) le = t-1;
    else if (canReach(i, t)) le = t;
    else if (canReach(i, t+1)) le = t-1;
    else return -1;

    while (le < ri) {
        ll mid = (le+ri+1)/2;
        if (canReach(i, mid)) le = mid;
        else ri = mid-1;
    }

    return le;
}

map<ll, int> cnt;

int main() {
	setIO();

    cin >> n >> r;
    FOR(i,1, n) cin >> a[i] >> b[i] >> c[i] >> d[i];
    FOR(i, 1, n) dx[i] = c[i] - a[i], dy[i] = d[i] - b[i];

    FOR(i, 1, n) {
        ld t = getOptTime (i);
       // cout << " i = " << i << " t= " << t << endl;

        ll tt = round(t);
      //  cout << " tt = " << tt << endl;

        ll fr = getFrBounds (i, tt);
        ll to = getToBounds (i, tt);

        //cout << " fr = " << fr << " to  = " << to << endl;

        if (fr <= to) {
            cnt[fr]++;
            cnt[to+1]--;
        }
    }

    int ans = 0;
    int cur = 0;
    for (auto p : cnt) {
        cur += p.s;
        if (p.f >= 0)
            ans = max(ans, cur);
    }
    cout << ans << "\n";

	return 0;
}

Compilation message

noras.cpp: In function 'void setIO(std::string)':
noras.cpp:34:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   34 |   freopen((s+".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
noras.cpp:35:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   35 |  freopen((s+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 5 ms 492 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 3 ms 492 KB Output is correct
6 Correct 3 ms 492 KB Output is correct
7 Correct 3 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 4 ms 492 KB Output is correct
15 Correct 4 ms 492 KB Output is correct
16 Correct 5 ms 492 KB Output is correct
17 Correct 4 ms 492 KB Output is correct
18 Correct 4 ms 492 KB Output is correct
19 Correct 4 ms 492 KB Output is correct
20 Correct 4 ms 492 KB Output is correct
21 Correct 4 ms 492 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 5 ms 492 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 3 ms 492 KB Output is correct
6 Correct 3 ms 492 KB Output is correct
7 Correct 3 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 4 ms 492 KB Output is correct
15 Correct 4 ms 492 KB Output is correct
16 Correct 5 ms 492 KB Output is correct
17 Correct 4 ms 492 KB Output is correct
18 Correct 4 ms 492 KB Output is correct
19 Correct 4 ms 492 KB Output is correct
20 Correct 4 ms 492 KB Output is correct
21 Correct 4 ms 492 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 252 ms 5244 KB Output is correct
24 Correct 248 ms 6636 KB Output is correct
25 Correct 249 ms 6764 KB Output is correct
26 Correct 254 ms 6764 KB Output is correct
27 Correct 269 ms 6892 KB Output is correct
28 Correct 267 ms 6764 KB Output is correct
29 Correct 311 ms 7020 KB Output is correct
30 Correct 275 ms 6896 KB Output is correct
31 Correct 273 ms 6892 KB Output is correct
32 Correct 342 ms 6892 KB Output is correct
33 Correct 331 ms 6944 KB Output is correct
34 Correct 331 ms 6892 KB Output is correct
35 Correct 331 ms 7020 KB Output is correct
36 Correct 345 ms 6892 KB Output is correct
37 Correct 300 ms 6712 KB Output is correct
38 Correct 300 ms 6636 KB Output is correct
39 Correct 296 ms 6636 KB Output is correct
40 Correct 317 ms 6720 KB Output is correct
41 Correct 300 ms 6636 KB Output is correct
42 Correct 298 ms 6764 KB Output is correct
43 Correct 749 ms 15468 KB Output is correct
44 Correct 733 ms 15596 KB Output is correct
45 Correct 740 ms 15468 KB Output is correct
46 Correct 740 ms 15468 KB Output is correct
47 Correct 740 ms 15340 KB Output is correct
48 Correct 672 ms 13420 KB Output is correct
49 Correct 668 ms 13292 KB Output is correct
50 Correct 669 ms 13420 KB Output is correct
51 Correct 660 ms 13292 KB Output is correct
52 Correct 660 ms 13460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 5 ms 492 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 3 ms 492 KB Output is correct
6 Correct 3 ms 492 KB Output is correct
7 Correct 3 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 4 ms 492 KB Output is correct
15 Correct 4 ms 492 KB Output is correct
16 Correct 5 ms 492 KB Output is correct
17 Correct 4 ms 492 KB Output is correct
18 Correct 4 ms 492 KB Output is correct
19 Correct 4 ms 492 KB Output is correct
20 Correct 4 ms 492 KB Output is correct
21 Correct 4 ms 492 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 3 ms 492 KB Output is correct
25 Correct 4 ms 492 KB Output is correct
26 Correct 3 ms 492 KB Output is correct
27 Correct 4 ms 492 KB Output is correct
28 Correct 4 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 5 ms 492 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 3 ms 492 KB Output is correct
6 Correct 3 ms 492 KB Output is correct
7 Correct 3 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 4 ms 492 KB Output is correct
15 Correct 4 ms 492 KB Output is correct
16 Correct 5 ms 492 KB Output is correct
17 Correct 4 ms 492 KB Output is correct
18 Correct 4 ms 492 KB Output is correct
19 Correct 4 ms 492 KB Output is correct
20 Correct 4 ms 492 KB Output is correct
21 Correct 4 ms 492 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 252 ms 5244 KB Output is correct
24 Correct 248 ms 6636 KB Output is correct
25 Correct 249 ms 6764 KB Output is correct
26 Correct 254 ms 6764 KB Output is correct
27 Correct 269 ms 6892 KB Output is correct
28 Correct 267 ms 6764 KB Output is correct
29 Correct 311 ms 7020 KB Output is correct
30 Correct 275 ms 6896 KB Output is correct
31 Correct 273 ms 6892 KB Output is correct
32 Correct 342 ms 6892 KB Output is correct
33 Correct 331 ms 6944 KB Output is correct
34 Correct 331 ms 6892 KB Output is correct
35 Correct 331 ms 7020 KB Output is correct
36 Correct 345 ms 6892 KB Output is correct
37 Correct 300 ms 6712 KB Output is correct
38 Correct 300 ms 6636 KB Output is correct
39 Correct 296 ms 6636 KB Output is correct
40 Correct 317 ms 6720 KB Output is correct
41 Correct 300 ms 6636 KB Output is correct
42 Correct 298 ms 6764 KB Output is correct
43 Correct 749 ms 15468 KB Output is correct
44 Correct 733 ms 15596 KB Output is correct
45 Correct 740 ms 15468 KB Output is correct
46 Correct 740 ms 15468 KB Output is correct
47 Correct 740 ms 15340 KB Output is correct
48 Correct 672 ms 13420 KB Output is correct
49 Correct 668 ms 13292 KB Output is correct
50 Correct 669 ms 13420 KB Output is correct
51 Correct 660 ms 13292 KB Output is correct
52 Correct 660 ms 13460 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 3 ms 492 KB Output is correct
55 Correct 4 ms 492 KB Output is correct
56 Correct 3 ms 492 KB Output is correct
57 Correct 4 ms 492 KB Output is correct
58 Correct 4 ms 492 KB Output is correct
59 Correct 255 ms 6636 KB Output is correct
60 Correct 262 ms 7276 KB Output is correct
61 Correct 256 ms 7148 KB Output is correct
62 Correct 245 ms 7020 KB Output is correct
63 Correct 320 ms 7788 KB Output is correct
64 Correct 334 ms 7660 KB Output is correct
65 Correct 320 ms 7740 KB Output is correct
66 Correct 315 ms 7660 KB Output is correct
67 Correct 358 ms 7788 KB Output is correct
68 Correct 337 ms 7020 KB Output is correct
69 Correct 334 ms 7020 KB Output is correct
70 Correct 335 ms 7020 KB Output is correct
71 Correct 338 ms 7148 KB Output is correct
72 Correct 341 ms 7148 KB Output is correct
73 Correct 332 ms 6764 KB Output is correct
74 Correct 306 ms 6636 KB Output is correct
75 Correct 326 ms 6716 KB Output is correct
76 Correct 307 ms 6892 KB Output is correct
77 Correct 712 ms 15340 KB Output is correct
78 Correct 725 ms 15468 KB Output is correct
79 Correct 729 ms 15360 KB Output is correct
80 Correct 744 ms 15356 KB Output is correct
81 Correct 701 ms 15340 KB Output is correct
82 Correct 671 ms 13676 KB Output is correct
83 Correct 697 ms 13804 KB Output is correct
84 Correct 686 ms 13692 KB Output is correct
85 Correct 708 ms 13708 KB Output is correct
86 Correct 701 ms 13804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 5 ms 492 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 3 ms 492 KB Output is correct
6 Correct 3 ms 492 KB Output is correct
7 Correct 3 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 4 ms 492 KB Output is correct
15 Correct 4 ms 492 KB Output is correct
16 Correct 5 ms 492 KB Output is correct
17 Correct 4 ms 492 KB Output is correct
18 Correct 4 ms 492 KB Output is correct
19 Correct 4 ms 492 KB Output is correct
20 Correct 4 ms 492 KB Output is correct
21 Correct 4 ms 492 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 252 ms 5244 KB Output is correct
24 Correct 248 ms 6636 KB Output is correct
25 Correct 249 ms 6764 KB Output is correct
26 Correct 254 ms 6764 KB Output is correct
27 Correct 269 ms 6892 KB Output is correct
28 Correct 267 ms 6764 KB Output is correct
29 Correct 311 ms 7020 KB Output is correct
30 Correct 275 ms 6896 KB Output is correct
31 Correct 273 ms 6892 KB Output is correct
32 Correct 342 ms 6892 KB Output is correct
33 Correct 331 ms 6944 KB Output is correct
34 Correct 331 ms 6892 KB Output is correct
35 Correct 331 ms 7020 KB Output is correct
36 Correct 345 ms 6892 KB Output is correct
37 Correct 300 ms 6712 KB Output is correct
38 Correct 300 ms 6636 KB Output is correct
39 Correct 296 ms 6636 KB Output is correct
40 Correct 317 ms 6720 KB Output is correct
41 Correct 300 ms 6636 KB Output is correct
42 Correct 298 ms 6764 KB Output is correct
43 Correct 749 ms 15468 KB Output is correct
44 Correct 733 ms 15596 KB Output is correct
45 Correct 740 ms 15468 KB Output is correct
46 Correct 740 ms 15468 KB Output is correct
47 Correct 740 ms 15340 KB Output is correct
48 Correct 672 ms 13420 KB Output is correct
49 Correct 668 ms 13292 KB Output is correct
50 Correct 669 ms 13420 KB Output is correct
51 Correct 660 ms 13292 KB Output is correct
52 Correct 660 ms 13460 KB Output is correct
53 Correct 255 ms 6636 KB Output is correct
54 Correct 262 ms 7276 KB Output is correct
55 Correct 256 ms 7148 KB Output is correct
56 Correct 245 ms 7020 KB Output is correct
57 Correct 320 ms 7788 KB Output is correct
58 Correct 334 ms 7660 KB Output is correct
59 Correct 320 ms 7740 KB Output is correct
60 Correct 315 ms 7660 KB Output is correct
61 Correct 358 ms 7788 KB Output is correct
62 Correct 337 ms 7020 KB Output is correct
63 Correct 334 ms 7020 KB Output is correct
64 Correct 335 ms 7020 KB Output is correct
65 Correct 338 ms 7148 KB Output is correct
66 Correct 341 ms 7148 KB Output is correct
67 Correct 332 ms 6764 KB Output is correct
68 Correct 306 ms 6636 KB Output is correct
69 Correct 326 ms 6716 KB Output is correct
70 Correct 307 ms 6892 KB Output is correct
71 Correct 712 ms 15340 KB Output is correct
72 Correct 725 ms 15468 KB Output is correct
73 Correct 729 ms 15360 KB Output is correct
74 Correct 744 ms 15356 KB Output is correct
75 Correct 701 ms 15340 KB Output is correct
76 Correct 671 ms 13676 KB Output is correct
77 Correct 697 ms 13804 KB Output is correct
78 Correct 686 ms 13692 KB Output is correct
79 Correct 708 ms 13708 KB Output is correct
80 Correct 701 ms 13804 KB Output is correct
81 Correct 1 ms 364 KB Output is correct
82 Correct 3 ms 492 KB Output is correct
83 Correct 4 ms 492 KB Output is correct
84 Correct 3 ms 492 KB Output is correct
85 Correct 4 ms 492 KB Output is correct
86 Correct 4 ms 492 KB Output is correct
87 Correct 357 ms 13640 KB Output is correct
88 Correct 349 ms 13292 KB Output is correct
89 Correct 319 ms 12040 KB Output is correct
90 Correct 306 ms 10860 KB Output is correct
91 Correct 283 ms 10092 KB Output is correct
92 Correct 376 ms 13568 KB Output is correct
93 Correct 398 ms 13676 KB Output is correct
94 Correct 373 ms 13820 KB Output is correct
95 Correct 380 ms 13804 KB Output is correct
96 Correct 375 ms 13884 KB Output is correct
97 Correct 177 ms 7532 KB Output is correct
98 Correct 204 ms 7532 KB Output is correct
99 Correct 179 ms 7532 KB Output is correct
100 Correct 175 ms 7532 KB Output is correct
101 Correct 188 ms 7404 KB Output is correct
102 Correct 186 ms 7404 KB Output is correct
103 Correct 187 ms 7532 KB Output is correct
104 Correct 183 ms 7404 KB Output is correct
105 Correct 189 ms 7660 KB Output is correct
106 Correct 184 ms 7404 KB Output is correct