#include <stdio.h>
#define N 500
#define MD 1000000007
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int vv[N + 1];
void init() {
int i;
for (i = 1; i <= N; i++)
vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD;
}
int xx[N * 2];
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)
if (xx[ii[j]] == xx[i_])
j++;
else if (xx[ii[j]] < xx[i_]) {
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 main() {
static int ii[N * 2], xx_[N * 2], dp[N + 1];
int n, h, i, j, ans;
init();
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &xx[i << 1 | 0], &xx[i << 1 | 1]);
xx[i << 1 | 1]++;
}
for (i = 0; i < n * 2; i++)
ii[i] = i;
sort(ii, 0, n * 2);
for (i = 0; i < n * 2; i++)
xx_[i] = xx[ii[i]], xx[ii[i]] = i;
dp[0] = 1;
for (h = 0; h + 1 < n * 2; h++) {
int x = xx_[h + 1] - xx_[h];
if (x > 0)
for (j = n; j > 0; j--)
if (xx[j - 1 << 1 | 0] <= h && h < xx[j - 1 << 1 | 1]) {
int k, c;
k = 0, c = 1;
for (i = j - 1; i >= 0; i--) {
if (xx[i << 1 | 0] <= h && h < xx[i << 1 | 1])
k++, c = (long long) c * (x - 1 + k) % MD * vv[k] % MD;
dp[j] = (dp[j] + (long long) dp[i] * c) % MD;
}
}
}
ans = 0;
for (i = 1; i <= n; i++)
ans = (ans + dp[i]) % MD;
printf("%d\n", ans);
return 0;
}
Compilation message
boat.c: In function 'main':
boat.c:63:14: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
63 | if (xx[j - 1 << 1 | 0] <= h && h < xx[j - 1 << 1 | 1]) {
| ~~^~~
boat.c:63:45: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
63 | if (xx[j - 1 << 1 | 0] <= h && h < xx[j - 1 << 1 | 1]) {
| ~~^~~
boat.c:47:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
47 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
boat.c:49:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
49 | scanf("%d%d", &xx[i << 1 | 0], &xx[i << 1 | 1]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
5 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
5 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
512 KB |
Output is correct |
21 |
Correct |
283 ms |
492 KB |
Output is correct |
22 |
Correct |
278 ms |
492 KB |
Output is correct |
23 |
Correct |
268 ms |
364 KB |
Output is correct |
24 |
Correct |
269 ms |
364 KB |
Output is correct |
25 |
Correct |
271 ms |
492 KB |
Output is correct |
26 |
Correct |
518 ms |
492 KB |
Output is correct |
27 |
Correct |
539 ms |
492 KB |
Output is correct |
28 |
Correct |
525 ms |
492 KB |
Output is correct |
29 |
Correct |
512 ms |
492 KB |
Output is correct |
30 |
Correct |
3 ms |
364 KB |
Output is correct |
31 |
Correct |
3 ms |
364 KB |
Output is correct |
32 |
Correct |
3 ms |
364 KB |
Output is correct |
33 |
Correct |
3 ms |
364 KB |
Output is correct |
34 |
Correct |
3 ms |
364 KB |
Output is correct |
35 |
Correct |
5 ms |
492 KB |
Output is correct |
36 |
Correct |
4 ms |
364 KB |
Output is correct |
37 |
Correct |
4 ms |
384 KB |
Output is correct |
38 |
Correct |
4 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Correct |
3 ms |
364 KB |
Output is correct |
4 |
Correct |
3 ms |
364 KB |
Output is correct |
5 |
Correct |
3 ms |
364 KB |
Output is correct |
6 |
Correct |
5 ms |
364 KB |
Output is correct |
7 |
Correct |
5 ms |
364 KB |
Output is correct |
8 |
Correct |
5 ms |
364 KB |
Output is correct |
9 |
Correct |
5 ms |
364 KB |
Output is correct |
10 |
Correct |
5 ms |
364 KB |
Output is correct |
11 |
Correct |
3 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
3 ms |
364 KB |
Output is correct |
14 |
Correct |
3 ms |
364 KB |
Output is correct |
15 |
Correct |
4 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
5 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
512 KB |
Output is correct |
21 |
Correct |
283 ms |
492 KB |
Output is correct |
22 |
Correct |
278 ms |
492 KB |
Output is correct |
23 |
Correct |
268 ms |
364 KB |
Output is correct |
24 |
Correct |
269 ms |
364 KB |
Output is correct |
25 |
Correct |
271 ms |
492 KB |
Output is correct |
26 |
Correct |
518 ms |
492 KB |
Output is correct |
27 |
Correct |
539 ms |
492 KB |
Output is correct |
28 |
Correct |
525 ms |
492 KB |
Output is correct |
29 |
Correct |
512 ms |
492 KB |
Output is correct |
30 |
Correct |
3 ms |
364 KB |
Output is correct |
31 |
Correct |
3 ms |
364 KB |
Output is correct |
32 |
Correct |
3 ms |
364 KB |
Output is correct |
33 |
Correct |
3 ms |
364 KB |
Output is correct |
34 |
Correct |
3 ms |
364 KB |
Output is correct |
35 |
Correct |
5 ms |
492 KB |
Output is correct |
36 |
Correct |
4 ms |
364 KB |
Output is correct |
37 |
Correct |
4 ms |
384 KB |
Output is correct |
38 |
Correct |
4 ms |
364 KB |
Output is correct |
39 |
Correct |
3 ms |
364 KB |
Output is correct |
40 |
Correct |
3 ms |
364 KB |
Output is correct |
41 |
Correct |
3 ms |
364 KB |
Output is correct |
42 |
Correct |
3 ms |
364 KB |
Output is correct |
43 |
Correct |
3 ms |
364 KB |
Output is correct |
44 |
Correct |
5 ms |
364 KB |
Output is correct |
45 |
Correct |
5 ms |
364 KB |
Output is correct |
46 |
Correct |
5 ms |
364 KB |
Output is correct |
47 |
Correct |
5 ms |
364 KB |
Output is correct |
48 |
Correct |
5 ms |
364 KB |
Output is correct |
49 |
Correct |
3 ms |
364 KB |
Output is correct |
50 |
Correct |
2 ms |
364 KB |
Output is correct |
51 |
Correct |
3 ms |
364 KB |
Output is correct |
52 |
Correct |
3 ms |
364 KB |
Output is correct |
53 |
Correct |
4 ms |
364 KB |
Output is correct |
54 |
Correct |
2 ms |
364 KB |
Output is correct |
55 |
Correct |
2 ms |
364 KB |
Output is correct |
56 |
Correct |
2 ms |
364 KB |
Output is correct |
57 |
Correct |
2 ms |
364 KB |
Output is correct |
58 |
Correct |
2 ms |
364 KB |
Output is correct |
59 |
Correct |
309 ms |
380 KB |
Output is correct |
60 |
Correct |
286 ms |
380 KB |
Output is correct |
61 |
Correct |
272 ms |
364 KB |
Output is correct |
62 |
Correct |
307 ms |
380 KB |
Output is correct |
63 |
Correct |
295 ms |
364 KB |
Output is correct |
64 |
Correct |
593 ms |
492 KB |
Output is correct |
65 |
Correct |
595 ms |
492 KB |
Output is correct |
66 |
Correct |
599 ms |
492 KB |
Output is correct |
67 |
Correct |
592 ms |
492 KB |
Output is correct |
68 |
Correct |
593 ms |
492 KB |
Output is correct |
69 |
Correct |
250 ms |
364 KB |
Output is correct |
70 |
Correct |
249 ms |
492 KB |
Output is correct |
71 |
Correct |
249 ms |
364 KB |
Output is correct |
72 |
Correct |
263 ms |
492 KB |
Output is correct |
73 |
Correct |
267 ms |
492 KB |
Output is correct |
74 |
Correct |
59 ms |
364 KB |
Output is correct |
75 |
Correct |
56 ms |
364 KB |
Output is correct |
76 |
Correct |
59 ms |
364 KB |
Output is correct |
77 |
Correct |
61 ms |
492 KB |
Output is correct |
78 |
Correct |
62 ms |
364 KB |
Output is correct |