# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
486465 |
2021-11-11T18:00:27 Z |
rainboy |
Relay (COI16_relay) |
C |
|
2000 ms |
6980 KB |
#include <stdio.h>
#define N 100000
#define M 100000
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
long long cross2(int x1, int y1, int x2, int y2) {
return (long long) x1 * y2 - (long long) x2 * y1;
}
long long cross(int x0, int y0, int x1, int y1, int x2, int y2) {
return cross2(x1 - x0, y1 - y0, x2 - x0, y2 - y0);
}
int xx[N + M], yy[N + M], xx_[N * 2], yy_[N * 2], idx[N * 2];
int compare(int x1, int y1, int x2, int y2) {
int sgn1 = x1 < 0 || x1 == 0 && y1 < 0 ? -1 : 1;
int sgn2 = x2 < 0 || x2 == 0 && y2 < 0 ? -1 : 1;
long long c;
if (sgn1 != sgn2)
return sgn1 - sgn2;
c = cross2(x1, y1, x2, y2);
return c == 0 ? 0 : (c > 0 ? -1 : 1);
}
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = compare(xx_[ii[j]], yy_[ii[j]], xx_[i_], yy_[i_]);
if (c == 0)
j++;
else if (c < 0) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
}
sort(ii, l, i);
l = k;
}
}
int intersect(int l1, int r1, int l2, int r2) {
int l1r1 = l1 <= r1, r1l2 = r1 < l2, l2r2 = l2 <= r2, r2l1 = r2 < l1;
return !(l1r1 && r1l2 && l2r2 || r1l2 && l2r2 && r2l1 || l2r2 && r2l1 && l1r1 || r2l1 && l1r1 && r1l2);
}
int main() {
static int ii[N * 2], dd[N * 2 + 1];
int n, n_, m, i, j, p, q, k;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d%d", &xx[i], &yy[i]);
scanf("%d", &m);
for (j = 0; j < m; j++)
scanf("%d%d", &xx[n + j], &yy[n + j]);
for (i = 0; i < n; i++)
for (j = 0; j < m; j++) {
p = (j - 1 + m) % m, q = (j + 1) % m;
if (cross(xx[i], yy[i], xx[n + p], yy[n + p], xx[n + j], yy[n + j]) >= 0
&& cross(xx[i], yy[i], xx[n + q], yy[n + q], xx[n + j], yy[n + j]) > 0)
xx_[i << 1 | 0] = xx[i] - xx[n + j], yy_[i << 1 | 0] = yy[i] - yy[n + j];
if (cross(xx[i], yy[i], xx[n + q], yy[n + q], xx[n + j], yy[n + j]) <= 0
&& cross(xx[i], yy[i], xx[n + p], yy[n + p], xx[n + j], yy[n + j]) < 0)
xx_[i << 1 | 1] = xx[n + j] - xx[i], yy_[i << 1 | 1] = yy[n + j] - yy[i];
}
for (i = 0; i < n * 2; i++)
ii[i] = i;
sort(ii, 0, n * 2);
for (i = 0, n_ = 0; i < n * 2; i++)
idx[ii[i]] = i + 1 == n * 2 || compare(xx_[ii[i + 1]], yy_[ii[i + 1]], xx_[ii[i]], yy_[ii[i]]) != 0 ? n_++ : n_;
for (i = 1; i < n; i++) {
int l = idx[i << 1 | 0], r = idx[i << 1 | 1];
if (intersect(idx[0 << 1 | 0], idx[0 << 1 | 1], l, r)) {
if (l < r)
dd[l]++, dd[r + 1]--;
else
dd[l]++, dd[n_]--, dd[0]++, dd[r + 1]--;
}
}
for (i = 1; i < n_; i++)
dd[i] += dd[i - 1];
for (i = 0; i < n_; i++)
if (dd[i] > 0)
dd[i] = 1;
for (i = 1; i < n_; i++)
dd[i] += dd[i - 1];
k = 0;
for (i = 1; i < n; i++) {
int l = idx[i << 1 | 0], r = idx[i << 1 | 1];
if ((l < r ? dd[r] - (l == 0 ? 0 : dd[l - 1]) : dd[n_ - 1] - dd[l - 1] + dd[r]) > 0)
k++;
}
printf("%d\n", k);
return 0;
}
Compilation message
relay.c: In function 'compare':
relay.c:23:31: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
23 | int sgn1 = x1 < 0 || x1 == 0 && y1 < 0 ? -1 : 1;
| ~~~~~~~~^~~~~~~~~
relay.c:24:31: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
24 | int sgn2 = x2 < 0 || x2 == 0 && y2 < 0 ? -1 : 1;
| ~~~~~~~~^~~~~~~~~
relay.c: In function 'intersect':
relay.c:58:24: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
58 | return !(l1r1 && r1l2 && l2r2 || r1l2 && l2r2 && r2l1 || l2r2 && r2l1 && l1r1 || r2l1 && l1r1 && r1l2);
| ~~~~~~~~~~~~~^~~~~~~
relay.c:58:72: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
58 | return !(l1r1 && r1l2 && l2r2 || r1l2 && l2r2 && r2l1 || l2r2 && r2l1 && l1r1 || r2l1 && l1r1 && r1l2);
| ~~~~~~~~~~~~~^~~~~~~
relay.c:58:96: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
58 | return !(l1r1 && r1l2 && l2r2 || r1l2 && l2r2 && r2l1 || l2r2 && r2l1 && l1r1 || r2l1 && l1r1 && r1l2);
| ~~~~~~~~~~~~~^~~~~~~
relay.c: In function 'main':
relay.c:65:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
relay.c:67:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | scanf("%d%d", &xx[i], &yy[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
relay.c:68:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | scanf("%d", &m);
| ^~~~~~~~~~~~~~~
relay.c:70:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | scanf("%d%d", &xx[n + j], &yy[n + j]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
91 ms |
356 KB |
Output is correct |
12 |
Correct |
90 ms |
580 KB |
Output is correct |
13 |
Correct |
48 ms |
452 KB |
Output is correct |
14 |
Correct |
52 ms |
428 KB |
Output is correct |
15 |
Correct |
43 ms |
452 KB |
Output is correct |
16 |
Correct |
44 ms |
432 KB |
Output is correct |
17 |
Correct |
46 ms |
444 KB |
Output is correct |
18 |
Correct |
51 ms |
432 KB |
Output is correct |
19 |
Correct |
50 ms |
564 KB |
Output is correct |
20 |
Correct |
48 ms |
432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
327 ms |
4952 KB |
Output is correct |
12 |
Correct |
342 ms |
6860 KB |
Output is correct |
13 |
Correct |
199 ms |
6852 KB |
Output is correct |
14 |
Correct |
194 ms |
6936 KB |
Output is correct |
15 |
Correct |
218 ms |
6932 KB |
Output is correct |
16 |
Correct |
222 ms |
6980 KB |
Output is correct |
17 |
Correct |
209 ms |
6856 KB |
Output is correct |
18 |
Correct |
226 ms |
6940 KB |
Output is correct |
19 |
Correct |
216 ms |
6852 KB |
Output is correct |
20 |
Correct |
209 ms |
6888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
91 ms |
356 KB |
Output is correct |
12 |
Correct |
90 ms |
580 KB |
Output is correct |
13 |
Correct |
48 ms |
452 KB |
Output is correct |
14 |
Correct |
52 ms |
428 KB |
Output is correct |
15 |
Correct |
43 ms |
452 KB |
Output is correct |
16 |
Correct |
44 ms |
432 KB |
Output is correct |
17 |
Correct |
46 ms |
444 KB |
Output is correct |
18 |
Correct |
51 ms |
432 KB |
Output is correct |
19 |
Correct |
50 ms |
564 KB |
Output is correct |
20 |
Correct |
48 ms |
432 KB |
Output is correct |
21 |
Correct |
327 ms |
4952 KB |
Output is correct |
22 |
Correct |
342 ms |
6860 KB |
Output is correct |
23 |
Correct |
199 ms |
6852 KB |
Output is correct |
24 |
Correct |
194 ms |
6936 KB |
Output is correct |
25 |
Correct |
218 ms |
6932 KB |
Output is correct |
26 |
Correct |
222 ms |
6980 KB |
Output is correct |
27 |
Correct |
209 ms |
6856 KB |
Output is correct |
28 |
Correct |
226 ms |
6940 KB |
Output is correct |
29 |
Correct |
216 ms |
6852 KB |
Output is correct |
30 |
Correct |
209 ms |
6888 KB |
Output is correct |
31 |
Execution timed out |
2080 ms |
5776 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |