#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 1005;
constexpr int MAXINT = 1073741823;
constexpr long long int MOD = 1000000007;
pair<long long int, long long int> a[MAXN];
vector<long long int> blocks;
long long int inverted[MAXN];
long long int ways[MAXN][MAXN], dp[MAXN][MAXN];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
inverted[0] = 1;
inverted[1] = 1;
for (long long int i = 2; i < MAXN; i++)
inverted[i] = inverted[MOD % i] * (MOD - MOD / i) % MOD;
long long int n, temporary;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
blocks.push_back(a[i].first - 1);
blocks.push_back(a[i].second);
}
sort(blocks.begin(), blocks.end());
blocks.resize(distance(blocks.begin(), unique(blocks.begin(), blocks.end())));
for (int i = 1; i < blocks.size(); i++) {
ways[i][0] = 1;
for (long long int j = 1; j <= n; j++) {
temporary = blocks[i] - blocks[i - 1];
for (long long int k = 1; k <= j && k <= blocks[i] - blocks[i - 1]; k++) {
ways[i][j] = (ways[i][j] + temporary) % MOD;
temporary = temporary * (blocks[i] - blocks[i - 1] - k) % MOD * inverted[k + 1] % MOD * (j - k) % MOD * inverted[k] % MOD;
}
}
}
fill(dp[0], dp[0] + MAXN, 1);
for (int i = 1; i <= n; i++) {
dp[i][0] = 1;
for (int j = 1; j < blocks.size(); j++) {
dp[i][j] = dp[i][j - 1];
temporary = 1;
for (int k = i; k >= 0; k--)
if (a[k].first <= blocks[j - 1] + 1 && blocks[j] <= a[k].second)
dp[i][j] = (dp[i][j] + dp[k - 1][j - 1] * ways[j][temporary++] % MOD) % MOD;
}
}
cout << dp[n][blocks.size() - 1] - 1;
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int i = 1; i < blocks.size(); i++) {
| ~~^~~~~~~~~~~~~~~
boat.cpp:48:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int j = 1; j < blocks.size(); j++) {
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1630 ms |
12140 KB |
Output is correct |
2 |
Correct |
1624 ms |
12024 KB |
Output is correct |
3 |
Correct |
1628 ms |
12132 KB |
Output is correct |
4 |
Correct |
1640 ms |
12272 KB |
Output is correct |
5 |
Correct |
1606 ms |
12104 KB |
Output is correct |
6 |
Correct |
1526 ms |
12280 KB |
Output is correct |
7 |
Correct |
1519 ms |
12148 KB |
Output is correct |
8 |
Correct |
1528 ms |
12144 KB |
Output is correct |
9 |
Correct |
1526 ms |
12240 KB |
Output is correct |
10 |
Correct |
1524 ms |
12148 KB |
Output is correct |
11 |
Correct |
1519 ms |
12084 KB |
Output is correct |
12 |
Correct |
1530 ms |
12144 KB |
Output is correct |
13 |
Correct |
1507 ms |
12208 KB |
Output is correct |
14 |
Correct |
1511 ms |
12192 KB |
Output is correct |
15 |
Correct |
1530 ms |
12056 KB |
Output is correct |
16 |
Correct |
304 ms |
4480 KB |
Output is correct |
17 |
Correct |
310 ms |
4584 KB |
Output is correct |
18 |
Correct |
311 ms |
4572 KB |
Output is correct |
19 |
Correct |
319 ms |
4600 KB |
Output is correct |
20 |
Correct |
310 ms |
4520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1630 ms |
12140 KB |
Output is correct |
2 |
Correct |
1624 ms |
12024 KB |
Output is correct |
3 |
Correct |
1628 ms |
12132 KB |
Output is correct |
4 |
Correct |
1640 ms |
12272 KB |
Output is correct |
5 |
Correct |
1606 ms |
12104 KB |
Output is correct |
6 |
Correct |
1526 ms |
12280 KB |
Output is correct |
7 |
Correct |
1519 ms |
12148 KB |
Output is correct |
8 |
Correct |
1528 ms |
12144 KB |
Output is correct |
9 |
Correct |
1526 ms |
12240 KB |
Output is correct |
10 |
Correct |
1524 ms |
12148 KB |
Output is correct |
11 |
Correct |
1519 ms |
12084 KB |
Output is correct |
12 |
Correct |
1530 ms |
12144 KB |
Output is correct |
13 |
Correct |
1507 ms |
12208 KB |
Output is correct |
14 |
Correct |
1511 ms |
12192 KB |
Output is correct |
15 |
Correct |
1530 ms |
12056 KB |
Output is correct |
16 |
Correct |
304 ms |
4480 KB |
Output is correct |
17 |
Correct |
310 ms |
4584 KB |
Output is correct |
18 |
Correct |
311 ms |
4572 KB |
Output is correct |
19 |
Correct |
319 ms |
4600 KB |
Output is correct |
20 |
Correct |
310 ms |
4520 KB |
Output is correct |
21 |
Correct |
522 ms |
11460 KB |
Output is correct |
22 |
Correct |
531 ms |
11616 KB |
Output is correct |
23 |
Correct |
490 ms |
11316 KB |
Output is correct |
24 |
Correct |
477 ms |
11236 KB |
Output is correct |
25 |
Correct |
510 ms |
11472 KB |
Output is correct |
26 |
Correct |
530 ms |
11280 KB |
Output is correct |
27 |
Correct |
559 ms |
11292 KB |
Output is correct |
28 |
Correct |
556 ms |
11092 KB |
Output is correct |
29 |
Correct |
549 ms |
11192 KB |
Output is correct |
30 |
Correct |
1457 ms |
12208 KB |
Output is correct |
31 |
Correct |
1474 ms |
12060 KB |
Output is correct |
32 |
Correct |
1484 ms |
12100 KB |
Output is correct |
33 |
Correct |
1475 ms |
12156 KB |
Output is correct |
34 |
Correct |
1455 ms |
12120 KB |
Output is correct |
35 |
Correct |
1568 ms |
12092 KB |
Output is correct |
36 |
Correct |
1567 ms |
12172 KB |
Output is correct |
37 |
Correct |
1577 ms |
12232 KB |
Output is correct |
38 |
Correct |
1538 ms |
12236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
1776 KB |
Output is correct |
2 |
Correct |
27 ms |
1908 KB |
Output is correct |
3 |
Correct |
28 ms |
1868 KB |
Output is correct |
4 |
Correct |
26 ms |
1860 KB |
Output is correct |
5 |
Correct |
26 ms |
1844 KB |
Output is correct |
6 |
Correct |
28 ms |
1848 KB |
Output is correct |
7 |
Correct |
27 ms |
1868 KB |
Output is correct |
8 |
Correct |
28 ms |
1896 KB |
Output is correct |
9 |
Correct |
27 ms |
1860 KB |
Output is correct |
10 |
Correct |
28 ms |
1788 KB |
Output is correct |
11 |
Correct |
28 ms |
1868 KB |
Output is correct |
12 |
Correct |
26 ms |
1808 KB |
Output is correct |
13 |
Correct |
27 ms |
1832 KB |
Output is correct |
14 |
Correct |
27 ms |
1908 KB |
Output is correct |
15 |
Correct |
26 ms |
1860 KB |
Output is correct |
16 |
Correct |
13 ms |
1328 KB |
Output is correct |
17 |
Correct |
12 ms |
1304 KB |
Output is correct |
18 |
Correct |
12 ms |
1356 KB |
Output is correct |
19 |
Correct |
12 ms |
1356 KB |
Output is correct |
20 |
Correct |
13 ms |
1356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1630 ms |
12140 KB |
Output is correct |
2 |
Correct |
1624 ms |
12024 KB |
Output is correct |
3 |
Correct |
1628 ms |
12132 KB |
Output is correct |
4 |
Correct |
1640 ms |
12272 KB |
Output is correct |
5 |
Correct |
1606 ms |
12104 KB |
Output is correct |
6 |
Correct |
1526 ms |
12280 KB |
Output is correct |
7 |
Correct |
1519 ms |
12148 KB |
Output is correct |
8 |
Correct |
1528 ms |
12144 KB |
Output is correct |
9 |
Correct |
1526 ms |
12240 KB |
Output is correct |
10 |
Correct |
1524 ms |
12148 KB |
Output is correct |
11 |
Correct |
1519 ms |
12084 KB |
Output is correct |
12 |
Correct |
1530 ms |
12144 KB |
Output is correct |
13 |
Correct |
1507 ms |
12208 KB |
Output is correct |
14 |
Correct |
1511 ms |
12192 KB |
Output is correct |
15 |
Correct |
1530 ms |
12056 KB |
Output is correct |
16 |
Correct |
304 ms |
4480 KB |
Output is correct |
17 |
Correct |
310 ms |
4584 KB |
Output is correct |
18 |
Correct |
311 ms |
4572 KB |
Output is correct |
19 |
Correct |
319 ms |
4600 KB |
Output is correct |
20 |
Correct |
310 ms |
4520 KB |
Output is correct |
21 |
Correct |
522 ms |
11460 KB |
Output is correct |
22 |
Correct |
531 ms |
11616 KB |
Output is correct |
23 |
Correct |
490 ms |
11316 KB |
Output is correct |
24 |
Correct |
477 ms |
11236 KB |
Output is correct |
25 |
Correct |
510 ms |
11472 KB |
Output is correct |
26 |
Correct |
530 ms |
11280 KB |
Output is correct |
27 |
Correct |
559 ms |
11292 KB |
Output is correct |
28 |
Correct |
556 ms |
11092 KB |
Output is correct |
29 |
Correct |
549 ms |
11192 KB |
Output is correct |
30 |
Correct |
1457 ms |
12208 KB |
Output is correct |
31 |
Correct |
1474 ms |
12060 KB |
Output is correct |
32 |
Correct |
1484 ms |
12100 KB |
Output is correct |
33 |
Correct |
1475 ms |
12156 KB |
Output is correct |
34 |
Correct |
1455 ms |
12120 KB |
Output is correct |
35 |
Correct |
1568 ms |
12092 KB |
Output is correct |
36 |
Correct |
1567 ms |
12172 KB |
Output is correct |
37 |
Correct |
1577 ms |
12232 KB |
Output is correct |
38 |
Correct |
1538 ms |
12236 KB |
Output is correct |
39 |
Correct |
26 ms |
1776 KB |
Output is correct |
40 |
Correct |
27 ms |
1908 KB |
Output is correct |
41 |
Correct |
28 ms |
1868 KB |
Output is correct |
42 |
Correct |
26 ms |
1860 KB |
Output is correct |
43 |
Correct |
26 ms |
1844 KB |
Output is correct |
44 |
Correct |
28 ms |
1848 KB |
Output is correct |
45 |
Correct |
27 ms |
1868 KB |
Output is correct |
46 |
Correct |
28 ms |
1896 KB |
Output is correct |
47 |
Correct |
27 ms |
1860 KB |
Output is correct |
48 |
Correct |
28 ms |
1788 KB |
Output is correct |
49 |
Correct |
28 ms |
1868 KB |
Output is correct |
50 |
Correct |
26 ms |
1808 KB |
Output is correct |
51 |
Correct |
27 ms |
1832 KB |
Output is correct |
52 |
Correct |
27 ms |
1908 KB |
Output is correct |
53 |
Correct |
26 ms |
1860 KB |
Output is correct |
54 |
Correct |
13 ms |
1328 KB |
Output is correct |
55 |
Correct |
12 ms |
1304 KB |
Output is correct |
56 |
Correct |
12 ms |
1356 KB |
Output is correct |
57 |
Correct |
12 ms |
1356 KB |
Output is correct |
58 |
Correct |
13 ms |
1356 KB |
Output is correct |
59 |
Execution timed out |
2087 ms |
6404 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |