#include <iostream>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
int n, c, a[509], b[509], x[1009], inv[509], comb[1009][509], dp[509][1009];
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
x[i] = a[i];
x[i + n] = ++b[i];
}
sort(x, x + 2 * n);
c = unique(x, x + 2 * n) - x;
for (int i = 0; i < n; ++i) {
a[i] = lower_bound(x, x + c, a[i]) - x;
b[i] = lower_bound(x, x + c, b[i]) - x;
}
inv[1] = 1;
for (int i = 2; i <= n; ++i) {
inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;
}
for (int i = 0; i < c - 1; ++i) {
int way = 1;
for (int j = 1; j <= n; ++j) {
way = 1LL * way * (x[i + 1] - x[i] - j + 1) % mod * inv[j] % mod;
comb[i][j] = comb[i][j - 1] + way;
if (comb[i][j] >= mod) comb[i][j] -= mod;
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = a[i]; j < b[i]; ++j) {
int num = 0;
for (int k = i - 1; k >= 0; --k) {
if (a[k + 1] <= j && j < b[k + 1]) ++num;
dp[i][j + 1] = (dp[i][j + 1] + 1LL * comb[j][num] * dp[k][j]) % mod;
}
if (a[0] <= j && j < b[0]) ++num;
dp[i][j + 1] += comb[j][num];
if (dp[i][j + 1] >= mod) dp[i][j + 1] -= mod;
}
for (int j = 0; j < c; ++j) {
dp[i][j + 1] += dp[i][j];
if (dp[i][j + 1] >= mod) dp[i][j + 1] -= mod;
}
ans += dp[i][c];
if (ans >= mod) ans -= mod;
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
4216 KB |
Output is correct |
2 |
Correct |
16 ms |
4324 KB |
Output is correct |
3 |
Correct |
15 ms |
4324 KB |
Output is correct |
4 |
Correct |
15 ms |
4360 KB |
Output is correct |
5 |
Correct |
15 ms |
4436 KB |
Output is correct |
6 |
Correct |
15 ms |
4436 KB |
Output is correct |
7 |
Correct |
15 ms |
4512 KB |
Output is correct |
8 |
Correct |
15 ms |
4512 KB |
Output is correct |
9 |
Correct |
15 ms |
4512 KB |
Output is correct |
10 |
Correct |
16 ms |
4588 KB |
Output is correct |
11 |
Correct |
15 ms |
4588 KB |
Output is correct |
12 |
Correct |
15 ms |
4588 KB |
Output is correct |
13 |
Correct |
15 ms |
4588 KB |
Output is correct |
14 |
Correct |
17 ms |
4588 KB |
Output is correct |
15 |
Correct |
16 ms |
4588 KB |
Output is correct |
16 |
Correct |
9 ms |
4588 KB |
Output is correct |
17 |
Correct |
7 ms |
4588 KB |
Output is correct |
18 |
Correct |
7 ms |
4588 KB |
Output is correct |
19 |
Correct |
7 ms |
4588 KB |
Output is correct |
20 |
Correct |
7 ms |
4588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
4216 KB |
Output is correct |
2 |
Correct |
16 ms |
4324 KB |
Output is correct |
3 |
Correct |
15 ms |
4324 KB |
Output is correct |
4 |
Correct |
15 ms |
4360 KB |
Output is correct |
5 |
Correct |
15 ms |
4436 KB |
Output is correct |
6 |
Correct |
15 ms |
4436 KB |
Output is correct |
7 |
Correct |
15 ms |
4512 KB |
Output is correct |
8 |
Correct |
15 ms |
4512 KB |
Output is correct |
9 |
Correct |
15 ms |
4512 KB |
Output is correct |
10 |
Correct |
16 ms |
4588 KB |
Output is correct |
11 |
Correct |
15 ms |
4588 KB |
Output is correct |
12 |
Correct |
15 ms |
4588 KB |
Output is correct |
13 |
Correct |
15 ms |
4588 KB |
Output is correct |
14 |
Correct |
17 ms |
4588 KB |
Output is correct |
15 |
Correct |
16 ms |
4588 KB |
Output is correct |
16 |
Correct |
9 ms |
4588 KB |
Output is correct |
17 |
Correct |
7 ms |
4588 KB |
Output is correct |
18 |
Correct |
7 ms |
4588 KB |
Output is correct |
19 |
Correct |
7 ms |
4588 KB |
Output is correct |
20 |
Correct |
7 ms |
4588 KB |
Output is correct |
21 |
Incorrect |
281 ms |
4588 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
4588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
4216 KB |
Output is correct |
2 |
Correct |
16 ms |
4324 KB |
Output is correct |
3 |
Correct |
15 ms |
4324 KB |
Output is correct |
4 |
Correct |
15 ms |
4360 KB |
Output is correct |
5 |
Correct |
15 ms |
4436 KB |
Output is correct |
6 |
Correct |
15 ms |
4436 KB |
Output is correct |
7 |
Correct |
15 ms |
4512 KB |
Output is correct |
8 |
Correct |
15 ms |
4512 KB |
Output is correct |
9 |
Correct |
15 ms |
4512 KB |
Output is correct |
10 |
Correct |
16 ms |
4588 KB |
Output is correct |
11 |
Correct |
15 ms |
4588 KB |
Output is correct |
12 |
Correct |
15 ms |
4588 KB |
Output is correct |
13 |
Correct |
15 ms |
4588 KB |
Output is correct |
14 |
Correct |
17 ms |
4588 KB |
Output is correct |
15 |
Correct |
16 ms |
4588 KB |
Output is correct |
16 |
Correct |
9 ms |
4588 KB |
Output is correct |
17 |
Correct |
7 ms |
4588 KB |
Output is correct |
18 |
Correct |
7 ms |
4588 KB |
Output is correct |
19 |
Correct |
7 ms |
4588 KB |
Output is correct |
20 |
Correct |
7 ms |
4588 KB |
Output is correct |
21 |
Incorrect |
281 ms |
4588 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |