Submission #375859

# Submission time Handle Problem Language Result Execution time Memory
375859 2021-03-10T05:32:18 Z _martynas Wish (LMIO19_noras) C++11
100 / 100
222 ms 17920 KB
#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second

using ll = long long;
using pll = pair<ll, ll>;

const int MAX_N = 200005;
const ll INF = 2e9;

struct Star
{
    pll pos;
    pll dir;
};

int N;
ll R;
Star Stars[MAX_N];

pll getNth(pll pos, pll dir, ll n)
{
    return make_pair(pos.F + n * dir.F, pos.S + n * dir.S);
}

ll getINF(pll dir)
{
    return INF / max(abs(dir.F), abs(dir.S));
}

ll closest(Star star)
{
    ll lo = 0, hi = getINF(star.dir);
    while(lo < hi)
    {
        ll mid = (lo + hi) / 2;
        pll pos1 = getNth(star.pos, star.dir, mid);
        pll pos2 = getNth(star.pos, star.dir, mid + 1);
        ll d1 = pos1.F * pos1.F + pos1.S * pos1.S;
        ll d2 = pos2.F * pos2.F + pos2.S * pos2.S;

        if(d1 == d2)
        {
            return mid;
        }
        else if(d1 < d2)
        {
            hi = mid;
        }
        else
        {
            lo = mid + 1;
        }
    }

    return lo;
}

int main()
{
    scanf("%d%lld", &N, &R);

    for(int i = 0; i < N; i++)
    {
        ll a, b, c, d;
        scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
        Stars[i] = {{a, b}, {c-a, d-b}};
    }

    vector<pll> Intervals;

    for(int i = 0; i < N; i++)
    {
        ll close = closest(Stars[i]);
        pll closestPos = getNth(Stars[i].pos, Stars[i].dir, close);
        if(closestPos.F * closestPos.F + closestPos.S * closestPos.S > R * R)
            continue;

        ll l = close, r = close;

        for(ll step = close; step > 0; step /= 2)
        {
            pll pos = getNth(Stars[i].pos, Stars[i].dir, l - step);
            while(l - step >= 0 && pos.F * pos.F + pos.S * pos.S <= R * R)
            {
                l -= step;
                pos = getNth(Stars[i].pos, Stars[i].dir, l - step);
            }
        }

        for(ll step = getINF(Stars[i].dir); step > 0; step /= 2)
        {
            pll pos = getNth(Stars[i].pos, Stars[i].dir, r + step);
            while(pos.F * pos.F + pos.S * pos.S <= R * R)
            {
                r += step;
                pos = getNth(Stars[i].pos, Stars[i].dir, r + step);
            }
        }

        Intervals.push_back({l, 1});
        Intervals.push_back({r + 1, -1});
    }

    sort(Intervals.begin(), Intervals.end());

    ll best = 0;
    ll curr = 0;

    for(pll p : Intervals)
    {
        curr += p.S;
        best = max(best, curr);
    }

    printf("%lld", best);

    return 0;
}

Compilation message

noras.cpp: In function 'int main()':
noras.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   64 |     scanf("%d%lld", &N, &R);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
noras.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   69 |         scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 380 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 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 380 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 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 68 ms 9308 KB Output is correct
24 Correct 66 ms 9308 KB Output is correct
25 Correct 68 ms 9308 KB Output is correct
26 Correct 67 ms 9308 KB Output is correct
27 Correct 65 ms 7540 KB Output is correct
28 Correct 83 ms 9564 KB Output is correct
29 Correct 75 ms 9692 KB Output is correct
30 Correct 74 ms 9436 KB Output is correct
31 Correct 74 ms 9584 KB Output is correct
32 Correct 96 ms 9524 KB Output is correct
33 Correct 95 ms 9436 KB Output is correct
34 Correct 104 ms 9436 KB Output is correct
35 Correct 111 ms 9456 KB Output is correct
36 Correct 96 ms 9436 KB Output is correct
37 Correct 72 ms 7264 KB Output is correct
38 Correct 72 ms 7264 KB Output is correct
39 Correct 70 ms 7264 KB Output is correct
40 Correct 72 ms 7264 KB Output is correct
41 Correct 71 ms 7264 KB Output is correct
42 Correct 71 ms 7264 KB Output is correct
43 Correct 218 ms 17620 KB Output is correct
44 Correct 217 ms 17624 KB Output is correct
45 Correct 222 ms 17620 KB Output is correct
46 Correct 213 ms 17620 KB Output is correct
47 Correct 213 ms 17620 KB Output is correct
48 Correct 196 ms 17648 KB Output is correct
49 Correct 194 ms 17620 KB Output is correct
50 Correct 197 ms 17920 KB Output is correct
51 Correct 195 ms 17620 KB Output is correct
52 Correct 192 ms 17624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 380 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 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 1 ms 396 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 380 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 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 68 ms 9308 KB Output is correct
24 Correct 66 ms 9308 KB Output is correct
25 Correct 68 ms 9308 KB Output is correct
26 Correct 67 ms 9308 KB Output is correct
27 Correct 65 ms 7540 KB Output is correct
28 Correct 83 ms 9564 KB Output is correct
29 Correct 75 ms 9692 KB Output is correct
30 Correct 74 ms 9436 KB Output is correct
31 Correct 74 ms 9584 KB Output is correct
32 Correct 96 ms 9524 KB Output is correct
33 Correct 95 ms 9436 KB Output is correct
34 Correct 104 ms 9436 KB Output is correct
35 Correct 111 ms 9456 KB Output is correct
36 Correct 96 ms 9436 KB Output is correct
37 Correct 72 ms 7264 KB Output is correct
38 Correct 72 ms 7264 KB Output is correct
39 Correct 70 ms 7264 KB Output is correct
40 Correct 72 ms 7264 KB Output is correct
41 Correct 71 ms 7264 KB Output is correct
42 Correct 71 ms 7264 KB Output is correct
43 Correct 218 ms 17620 KB Output is correct
44 Correct 217 ms 17624 KB Output is correct
45 Correct 222 ms 17620 KB Output is correct
46 Correct 213 ms 17620 KB Output is correct
47 Correct 213 ms 17620 KB Output is correct
48 Correct 196 ms 17648 KB Output is correct
49 Correct 194 ms 17620 KB Output is correct
50 Correct 197 ms 17920 KB Output is correct
51 Correct 195 ms 17620 KB Output is correct
52 Correct 192 ms 17624 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 1 ms 512 KB Output is correct
55 Correct 2 ms 492 KB Output is correct
56 Correct 1 ms 396 KB Output is correct
57 Correct 1 ms 492 KB Output is correct
58 Correct 1 ms 492 KB Output is correct
59 Correct 68 ms 9308 KB Output is correct
60 Correct 67 ms 7776 KB Output is correct
61 Correct 68 ms 7776 KB Output is correct
62 Correct 64 ms 7648 KB Output is correct
63 Correct 81 ms 7648 KB Output is correct
64 Correct 93 ms 7728 KB Output is correct
65 Correct 98 ms 7776 KB Output is correct
66 Correct 84 ms 7776 KB Output is correct
67 Correct 81 ms 7776 KB Output is correct
68 Correct 99 ms 9564 KB Output is correct
69 Correct 96 ms 9564 KB Output is correct
70 Correct 100 ms 9692 KB Output is correct
71 Correct 97 ms 9564 KB Output is correct
72 Correct 108 ms 9564 KB Output is correct
73 Correct 74 ms 7136 KB Output is correct
74 Correct 75 ms 9308 KB Output is correct
75 Correct 75 ms 9308 KB Output is correct
76 Correct 73 ms 7392 KB Output is correct
77 Correct 205 ms 17620 KB Output is correct
78 Correct 201 ms 17804 KB Output is correct
79 Correct 202 ms 17620 KB Output is correct
80 Correct 204 ms 17620 KB Output is correct
81 Correct 202 ms 17620 KB Output is correct
82 Correct 194 ms 17620 KB Output is correct
83 Correct 198 ms 17800 KB Output is correct
84 Correct 198 ms 17620 KB Output is correct
85 Correct 197 ms 17620 KB Output is correct
86 Correct 196 ms 17620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 380 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 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 68 ms 9308 KB Output is correct
24 Correct 66 ms 9308 KB Output is correct
25 Correct 68 ms 9308 KB Output is correct
26 Correct 67 ms 9308 KB Output is correct
27 Correct 65 ms 7540 KB Output is correct
28 Correct 83 ms 9564 KB Output is correct
29 Correct 75 ms 9692 KB Output is correct
30 Correct 74 ms 9436 KB Output is correct
31 Correct 74 ms 9584 KB Output is correct
32 Correct 96 ms 9524 KB Output is correct
33 Correct 95 ms 9436 KB Output is correct
34 Correct 104 ms 9436 KB Output is correct
35 Correct 111 ms 9456 KB Output is correct
36 Correct 96 ms 9436 KB Output is correct
37 Correct 72 ms 7264 KB Output is correct
38 Correct 72 ms 7264 KB Output is correct
39 Correct 70 ms 7264 KB Output is correct
40 Correct 72 ms 7264 KB Output is correct
41 Correct 71 ms 7264 KB Output is correct
42 Correct 71 ms 7264 KB Output is correct
43 Correct 218 ms 17620 KB Output is correct
44 Correct 217 ms 17624 KB Output is correct
45 Correct 222 ms 17620 KB Output is correct
46 Correct 213 ms 17620 KB Output is correct
47 Correct 213 ms 17620 KB Output is correct
48 Correct 196 ms 17648 KB Output is correct
49 Correct 194 ms 17620 KB Output is correct
50 Correct 197 ms 17920 KB Output is correct
51 Correct 195 ms 17620 KB Output is correct
52 Correct 192 ms 17624 KB Output is correct
53 Correct 68 ms 9308 KB Output is correct
54 Correct 67 ms 7776 KB Output is correct
55 Correct 68 ms 7776 KB Output is correct
56 Correct 64 ms 7648 KB Output is correct
57 Correct 81 ms 7648 KB Output is correct
58 Correct 93 ms 7728 KB Output is correct
59 Correct 98 ms 7776 KB Output is correct
60 Correct 84 ms 7776 KB Output is correct
61 Correct 81 ms 7776 KB Output is correct
62 Correct 99 ms 9564 KB Output is correct
63 Correct 96 ms 9564 KB Output is correct
64 Correct 100 ms 9692 KB Output is correct
65 Correct 97 ms 9564 KB Output is correct
66 Correct 108 ms 9564 KB Output is correct
67 Correct 74 ms 7136 KB Output is correct
68 Correct 75 ms 9308 KB Output is correct
69 Correct 75 ms 9308 KB Output is correct
70 Correct 73 ms 7392 KB Output is correct
71 Correct 205 ms 17620 KB Output is correct
72 Correct 201 ms 17804 KB Output is correct
73 Correct 202 ms 17620 KB Output is correct
74 Correct 204 ms 17620 KB Output is correct
75 Correct 202 ms 17620 KB Output is correct
76 Correct 194 ms 17620 KB Output is correct
77 Correct 198 ms 17800 KB Output is correct
78 Correct 198 ms 17620 KB Output is correct
79 Correct 197 ms 17620 KB Output is correct
80 Correct 196 ms 17620 KB Output is correct
81 Correct 1 ms 364 KB Output is correct
82 Correct 1 ms 512 KB Output is correct
83 Correct 2 ms 492 KB Output is correct
84 Correct 1 ms 396 KB Output is correct
85 Correct 1 ms 492 KB Output is correct
86 Correct 1 ms 492 KB Output is correct
87 Correct 100 ms 8288 KB Output is correct
88 Correct 90 ms 8032 KB Output is correct
89 Correct 89 ms 8032 KB Output is correct
90 Correct 88 ms 8032 KB Output is correct
91 Correct 85 ms 8032 KB Output is correct
92 Correct 100 ms 8032 KB Output is correct
93 Correct 99 ms 8032 KB Output is correct
94 Correct 100 ms 8032 KB Output is correct
95 Correct 99 ms 8160 KB Output is correct
96 Correct 121 ms 8032 KB Output is correct
97 Correct 114 ms 10144 KB Output is correct
98 Correct 60 ms 10076 KB Output is correct
99 Correct 63 ms 10076 KB Output is correct
100 Correct 63 ms 10204 KB Output is correct
101 Correct 60 ms 10076 KB Output is correct
102 Correct 60 ms 10076 KB Output is correct
103 Correct 61 ms 10076 KB Output is correct
104 Correct 60 ms 10076 KB Output is correct
105 Correct 62 ms 10076 KB Output is correct
106 Correct 62 ms 10076 KB Output is correct