# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
378435 |
2021-03-16T19:03:25 Z |
rainboy |
Boat (APIO16_boat) |
C |
|
511 ms |
512 KB |
#include <stdio.h>
#define N 500
#define MD 1000000007
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int vv[N + 1], ff[N + 1], gg[N + 1];
void init() {
int i;
ff[0] = gg[0] = 1;
for (i = 1; i <= N; i++) {
vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD;
ff[i] = (long long) ff[i - 1] * i % MD;
gg[i] = (long long) gg[i - 1] * vv[i] % 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;
}
}
long long choose(int n, int k) {
return (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}
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;
k = 0;
for (i = j - 1; i >= 0; i--) {
if (xx[i << 1 | 0] <= h && h < xx[i << 1 | 1])
k++;
dp[j] = (dp[j] + dp[i] * choose(k + x - 1, x - 1)) % 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:71:13: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
71 | if (xx[j - 1 << 1 | 0] <= h && h < xx[j - 1 << 1 | 1]) {
| ~~^~~
boat.c:71:44: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
71 | if (xx[j - 1 << 1 | 0] <= h && h < xx[j - 1 << 1 | 1]) {
| ~~^~~
boat.c:55:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
55 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
boat.c:57:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
57 | scanf("%d%d", &xx[i << 1 | 0], &xx[i << 1 | 1]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
384 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 |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
492 KB |
Output is correct |
8 |
Correct |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
3 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 |
3 ms |
384 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 |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
384 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 |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
492 KB |
Output is correct |
8 |
Correct |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
3 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 |
3 ms |
384 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 |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
364 KB |
Output is correct |
21 |
Correct |
376 ms |
512 KB |
Output is correct |
22 |
Correct |
364 ms |
492 KB |
Output is correct |
23 |
Correct |
339 ms |
492 KB |
Output is correct |
24 |
Correct |
365 ms |
364 KB |
Output is correct |
25 |
Correct |
367 ms |
364 KB |
Output is correct |
26 |
Incorrect |
511 ms |
492 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
364 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
384 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 |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
492 KB |
Output is correct |
8 |
Correct |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
3 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 |
3 ms |
384 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 |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
364 KB |
Output is correct |
21 |
Correct |
376 ms |
512 KB |
Output is correct |
22 |
Correct |
364 ms |
492 KB |
Output is correct |
23 |
Correct |
339 ms |
492 KB |
Output is correct |
24 |
Correct |
365 ms |
364 KB |
Output is correct |
25 |
Correct |
367 ms |
364 KB |
Output is correct |
26 |
Incorrect |
511 ms |
492 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |