# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
253171 |
2020-07-27T09:21:09 Z |
Nightlight |
Wish (LMIO19_noras) |
C++14 |
|
194 ms |
8188 KB |
#include <bits/stdc++.h>
#define point pair<long long, long long>
#define pii pair<int, bool>
using namespace std;
const long long limit = 2e8;
int N;
long long R;
long long a, b, c, d;
vector<pii> seg;
//a*x + b*y = c
//m = p/q
long long x_1, y_1, x_2, y_2, vx, vy;
long long p, q;
long double xx, yy;//terdekat
bool check(long long mid) {
long long a = x_1 + mid * vx, b = y_1 + mid * vy;
if(a > limit || a < -limit || b > limit || b < -limit) return 0;
return a * a + b * b <= R * R;
}
int main() {
ios_base::sync_with_stdio(0);
cin >> N >> R;
long long l, r, res, mid;
long long lb, ub;
for(int i = 1; i <= N; i++) {
cin >> x_1 >> y_1 >> x_2 >> y_2;
if(x_1 == x_2) swap(x_1, y_1), swap(x_2, y_2);
p = y_2 - y_1, q = x_2 - x_1;
vx = q, vy = p;
// cout << i << " " << p << " " << q << "\n";
xx = (long double)(q * y_1 - p * x_1) * -p / (q * q + p * p);
yy = (long double)(q * y_1 - p * x_1) * q / (q * q + p * p);
// cout << xx << " " << yy << "\n";
//kalau tedekat > R
if(xx * xx + yy * yy > R * R) continue;
//kalau ga bakal ketemu yang terdekat
if(((x_1 > x_2) ^ (x_1 > xx)) || ((y_1 > y_2) ^ (y_1 > yy)) || (x_1 == xx)) {
// cout << "A\n";
if(x_1 * x_1 + y_1 * y_1 > R * R) continue;
else {
l = 0, r = limit;
while(l <= r) {
mid = (l + r) >> 1;
if(check(mid)) {
l = mid + 1;
res = mid;
}else r = mid - 1;
}
seg.emplace_back(0, 1);
seg.emplace_back(res + 1, 0);
}
}else {
// cout << "B\n";
//cari yang bawah dulu
l = 0, r = floor((x_1 - xx) / (x_1 - x_2)), lb = -1;
while(l <= r) {
mid = (l + r) >> 1;
if(check(mid)) {
r = mid - 1;
lb = mid;
}else l = mid + 1;
}
l = lb, r = limit, ub = -1;
if(lb == -1) l = ceil((x_1 - xx) / (x_1 - x_2));
while(l <= r) {
mid = (l + r) >> 1;
if(check(mid)) {
l = mid + 1;
ub = mid;
}else r = mid - 1;
}
if(ub == -1 && lb == -1) continue;
if(ub == -1) ub = floor((x_1 - xx) / (x_1 - x_2));
if(lb == -1) lb = ceil((x_1 - xx) / (x_1 - x_2));
seg.emplace_back(lb, 1);
seg.emplace_back(ub + 1, 0);
}
}
sort(seg.begin(), seg.end());
seg.emplace_back(limit, 1);
//linesweep
long long now;
int cnt = 0, ans = 0;
for(int i = 0; i < seg.size() - 1;) {
now = seg[i].first;
while(now == seg[i].first) {
if(seg[i].second) cnt++;
else cnt--;
i++;
}
ans = max(ans, cnt);
}
cout << ans << "\n";
cin >> N;
}
Compilation message
noras.cpp: In function 'int main()':
noras.cpp:91:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < seg.size() - 1;) {
~~^~~~~~~~~~~~~~~~
noras.cpp:57:30: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
seg.emplace_back(res + 1, 0);
~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
80 ms |
3820 KB |
Output is correct |
24 |
Correct |
72 ms |
3844 KB |
Output is correct |
25 |
Correct |
74 ms |
3820 KB |
Output is correct |
26 |
Correct |
75 ms |
3824 KB |
Output is correct |
27 |
Correct |
61 ms |
3180 KB |
Output is correct |
28 |
Correct |
64 ms |
3952 KB |
Output is correct |
29 |
Correct |
63 ms |
3952 KB |
Output is correct |
30 |
Correct |
61 ms |
4080 KB |
Output is correct |
31 |
Correct |
63 ms |
3952 KB |
Output is correct |
32 |
Correct |
88 ms |
3948 KB |
Output is correct |
33 |
Correct |
82 ms |
3968 KB |
Output is correct |
34 |
Correct |
79 ms |
3964 KB |
Output is correct |
35 |
Correct |
93 ms |
3952 KB |
Output is correct |
36 |
Correct |
83 ms |
3952 KB |
Output is correct |
37 |
Correct |
83 ms |
3184 KB |
Output is correct |
38 |
Correct |
88 ms |
3052 KB |
Output is correct |
39 |
Correct |
70 ms |
3060 KB |
Output is correct |
40 |
Correct |
75 ms |
2932 KB |
Output is correct |
41 |
Correct |
78 ms |
3060 KB |
Output is correct |
42 |
Correct |
64 ms |
3188 KB |
Output is correct |
43 |
Correct |
185 ms |
8076 KB |
Output is correct |
44 |
Correct |
189 ms |
7904 KB |
Output is correct |
45 |
Correct |
183 ms |
7904 KB |
Output is correct |
46 |
Correct |
190 ms |
7912 KB |
Output is correct |
47 |
Correct |
194 ms |
8188 KB |
Output is correct |
48 |
Correct |
168 ms |
7144 KB |
Output is correct |
49 |
Correct |
180 ms |
7272 KB |
Output is correct |
50 |
Correct |
164 ms |
7140 KB |
Output is correct |
51 |
Correct |
161 ms |
7312 KB |
Output is correct |
52 |
Correct |
167 ms |
7144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
80 ms |
3820 KB |
Output is correct |
24 |
Correct |
72 ms |
3844 KB |
Output is correct |
25 |
Correct |
74 ms |
3820 KB |
Output is correct |
26 |
Correct |
75 ms |
3824 KB |
Output is correct |
27 |
Correct |
61 ms |
3180 KB |
Output is correct |
28 |
Correct |
64 ms |
3952 KB |
Output is correct |
29 |
Correct |
63 ms |
3952 KB |
Output is correct |
30 |
Correct |
61 ms |
4080 KB |
Output is correct |
31 |
Correct |
63 ms |
3952 KB |
Output is correct |
32 |
Correct |
88 ms |
3948 KB |
Output is correct |
33 |
Correct |
82 ms |
3968 KB |
Output is correct |
34 |
Correct |
79 ms |
3964 KB |
Output is correct |
35 |
Correct |
93 ms |
3952 KB |
Output is correct |
36 |
Correct |
83 ms |
3952 KB |
Output is correct |
37 |
Correct |
83 ms |
3184 KB |
Output is correct |
38 |
Correct |
88 ms |
3052 KB |
Output is correct |
39 |
Correct |
70 ms |
3060 KB |
Output is correct |
40 |
Correct |
75 ms |
2932 KB |
Output is correct |
41 |
Correct |
78 ms |
3060 KB |
Output is correct |
42 |
Correct |
64 ms |
3188 KB |
Output is correct |
43 |
Correct |
185 ms |
8076 KB |
Output is correct |
44 |
Correct |
189 ms |
7904 KB |
Output is correct |
45 |
Correct |
183 ms |
7904 KB |
Output is correct |
46 |
Correct |
190 ms |
7912 KB |
Output is correct |
47 |
Correct |
194 ms |
8188 KB |
Output is correct |
48 |
Correct |
168 ms |
7144 KB |
Output is correct |
49 |
Correct |
180 ms |
7272 KB |
Output is correct |
50 |
Correct |
164 ms |
7140 KB |
Output is correct |
51 |
Correct |
161 ms |
7312 KB |
Output is correct |
52 |
Correct |
167 ms |
7144 KB |
Output is correct |
53 |
Correct |
73 ms |
3824 KB |
Output is correct |
54 |
Correct |
64 ms |
3312 KB |
Output is correct |
55 |
Correct |
69 ms |
3312 KB |
Output is correct |
56 |
Correct |
73 ms |
3308 KB |
Output is correct |
57 |
Correct |
64 ms |
3268 KB |
Output is correct |
58 |
Correct |
64 ms |
3276 KB |
Output is correct |
59 |
Correct |
61 ms |
3312 KB |
Output is correct |
60 |
Correct |
63 ms |
3308 KB |
Output is correct |
61 |
Correct |
63 ms |
3188 KB |
Output is correct |
62 |
Correct |
85 ms |
4080 KB |
Output is correct |
63 |
Correct |
86 ms |
4080 KB |
Output is correct |
64 |
Correct |
81 ms |
4080 KB |
Output is correct |
65 |
Correct |
83 ms |
4080 KB |
Output is correct |
66 |
Correct |
83 ms |
4076 KB |
Output is correct |
67 |
Correct |
73 ms |
2924 KB |
Output is correct |
68 |
Correct |
77 ms |
4080 KB |
Output is correct |
69 |
Correct |
77 ms |
4080 KB |
Output is correct |
70 |
Correct |
71 ms |
3060 KB |
Output is correct |
71 |
Correct |
180 ms |
7916 KB |
Output is correct |
72 |
Correct |
188 ms |
7912 KB |
Output is correct |
73 |
Correct |
168 ms |
7912 KB |
Output is correct |
74 |
Correct |
167 ms |
7912 KB |
Output is correct |
75 |
Correct |
174 ms |
7912 KB |
Output is correct |
76 |
Correct |
172 ms |
7528 KB |
Output is correct |
77 |
Correct |
174 ms |
7400 KB |
Output is correct |
78 |
Correct |
176 ms |
7560 KB |
Output is correct |
79 |
Correct |
180 ms |
7400 KB |
Output is correct |
80 |
Correct |
173 ms |
7400 KB |
Output is correct |
81 |
Correct |
0 ms |
384 KB |
Output is correct |
82 |
Correct |
1 ms |
384 KB |
Output is correct |
83 |
Correct |
1 ms |
384 KB |
Output is correct |
84 |
Correct |
1 ms |
384 KB |
Output is correct |
85 |
Correct |
1 ms |
384 KB |
Output is correct |
86 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
80 ms |
3820 KB |
Output is correct |
24 |
Correct |
72 ms |
3844 KB |
Output is correct |
25 |
Correct |
74 ms |
3820 KB |
Output is correct |
26 |
Correct |
75 ms |
3824 KB |
Output is correct |
27 |
Correct |
61 ms |
3180 KB |
Output is correct |
28 |
Correct |
64 ms |
3952 KB |
Output is correct |
29 |
Correct |
63 ms |
3952 KB |
Output is correct |
30 |
Correct |
61 ms |
4080 KB |
Output is correct |
31 |
Correct |
63 ms |
3952 KB |
Output is correct |
32 |
Correct |
88 ms |
3948 KB |
Output is correct |
33 |
Correct |
82 ms |
3968 KB |
Output is correct |
34 |
Correct |
79 ms |
3964 KB |
Output is correct |
35 |
Correct |
93 ms |
3952 KB |
Output is correct |
36 |
Correct |
83 ms |
3952 KB |
Output is correct |
37 |
Correct |
83 ms |
3184 KB |
Output is correct |
38 |
Correct |
88 ms |
3052 KB |
Output is correct |
39 |
Correct |
70 ms |
3060 KB |
Output is correct |
40 |
Correct |
75 ms |
2932 KB |
Output is correct |
41 |
Correct |
78 ms |
3060 KB |
Output is correct |
42 |
Correct |
64 ms |
3188 KB |
Output is correct |
43 |
Correct |
185 ms |
8076 KB |
Output is correct |
44 |
Correct |
189 ms |
7904 KB |
Output is correct |
45 |
Correct |
183 ms |
7904 KB |
Output is correct |
46 |
Correct |
190 ms |
7912 KB |
Output is correct |
47 |
Correct |
194 ms |
8188 KB |
Output is correct |
48 |
Correct |
168 ms |
7144 KB |
Output is correct |
49 |
Correct |
180 ms |
7272 KB |
Output is correct |
50 |
Correct |
164 ms |
7140 KB |
Output is correct |
51 |
Correct |
161 ms |
7312 KB |
Output is correct |
52 |
Correct |
167 ms |
7144 KB |
Output is correct |
53 |
Correct |
73 ms |
3824 KB |
Output is correct |
54 |
Correct |
64 ms |
3312 KB |
Output is correct |
55 |
Correct |
69 ms |
3312 KB |
Output is correct |
56 |
Correct |
73 ms |
3308 KB |
Output is correct |
57 |
Correct |
64 ms |
3268 KB |
Output is correct |
58 |
Correct |
64 ms |
3276 KB |
Output is correct |
59 |
Correct |
61 ms |
3312 KB |
Output is correct |
60 |
Correct |
63 ms |
3308 KB |
Output is correct |
61 |
Correct |
63 ms |
3188 KB |
Output is correct |
62 |
Correct |
85 ms |
4080 KB |
Output is correct |
63 |
Correct |
86 ms |
4080 KB |
Output is correct |
64 |
Correct |
81 ms |
4080 KB |
Output is correct |
65 |
Correct |
83 ms |
4080 KB |
Output is correct |
66 |
Correct |
83 ms |
4076 KB |
Output is correct |
67 |
Correct |
73 ms |
2924 KB |
Output is correct |
68 |
Correct |
77 ms |
4080 KB |
Output is correct |
69 |
Correct |
77 ms |
4080 KB |
Output is correct |
70 |
Correct |
71 ms |
3060 KB |
Output is correct |
71 |
Correct |
180 ms |
7916 KB |
Output is correct |
72 |
Correct |
188 ms |
7912 KB |
Output is correct |
73 |
Correct |
168 ms |
7912 KB |
Output is correct |
74 |
Correct |
167 ms |
7912 KB |
Output is correct |
75 |
Correct |
174 ms |
7912 KB |
Output is correct |
76 |
Correct |
172 ms |
7528 KB |
Output is correct |
77 |
Correct |
174 ms |
7400 KB |
Output is correct |
78 |
Correct |
176 ms |
7560 KB |
Output is correct |
79 |
Correct |
180 ms |
7400 KB |
Output is correct |
80 |
Correct |
173 ms |
7400 KB |
Output is correct |
81 |
Correct |
90 ms |
4784 KB |
Output is correct |
82 |
Correct |
91 ms |
4844 KB |
Output is correct |
83 |
Correct |
86 ms |
4820 KB |
Output is correct |
84 |
Correct |
90 ms |
4848 KB |
Output is correct |
85 |
Correct |
90 ms |
4848 KB |
Output is correct |
86 |
Correct |
92 ms |
4764 KB |
Output is correct |
87 |
Correct |
97 ms |
4848 KB |
Output is correct |
88 |
Correct |
101 ms |
4848 KB |
Output is correct |
89 |
Correct |
91 ms |
4848 KB |
Output is correct |
90 |
Correct |
88 ms |
4720 KB |
Output is correct |
91 |
Correct |
82 ms |
4336 KB |
Output is correct |
92 |
Correct |
82 ms |
4460 KB |
Output is correct |
93 |
Correct |
82 ms |
4332 KB |
Output is correct |
94 |
Correct |
88 ms |
4336 KB |
Output is correct |
95 |
Correct |
82 ms |
4340 KB |
Output is correct |
96 |
Correct |
83 ms |
4360 KB |
Output is correct |
97 |
Correct |
86 ms |
4336 KB |
Output is correct |
98 |
Correct |
85 ms |
4336 KB |
Output is correct |
99 |
Correct |
86 ms |
4472 KB |
Output is correct |
100 |
Correct |
92 ms |
4336 KB |
Output is correct |
101 |
Correct |
0 ms |
384 KB |
Output is correct |
102 |
Correct |
1 ms |
384 KB |
Output is correct |
103 |
Correct |
1 ms |
384 KB |
Output is correct |
104 |
Correct |
1 ms |
384 KB |
Output is correct |
105 |
Correct |
1 ms |
384 KB |
Output is correct |
106 |
Correct |
1 ms |
384 KB |
Output is correct |