#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define all(aaa) aaa.begin(), aaa.end()
#pragma warning(disable : 4996)
const int N = 505, MOD = 1e9 + 7, M = N * 2;;
int a[N], b[N], dp[N][M], dp2[M][N], c[N][N], c2[N];
int n;
vector<int> occ[M];
ll bp(ll a, ll p) {
ll r = 1;
while (p > 0) {
if (p & 1)
r = r * a % MOD;
p >>= 1;
a = a * a % MOD;
}
return r;
}
void f(int& a, int b) {
a += b;
if (a >= MOD)
a -= MOD;
}
//const int M1 = 1e3 + 5, N1 = 10;
//int dpb[N1][M1];
//
//int slow() {
// dpb[0][0] = 1;
// int q = 0;
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < M1; j++) {
// f(dpb[i + 1][j], dpb[i][j]);
// }
// for (int j = 1; j < M1; j++) {
// f(dpb[i][j], dpb[i][j - 1]);
// }
// for (int j = a[i]; j <= b[i]; j++) {
// f(dpb[i + 1][j], dpb[i][j - 1]);
// }
// }
//
// for (int j = 1; j < M1; j++) {
// f(dpb[n][j], dpb[n][j - 1]);
// }
//
// return dpb[n][M1 - 1] - 1;
//}
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < N; i++) {
c[i][0] = 1;
}
for (int i = 1; i < N; i++) {
for (int j = 1; j < N; j++) {
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;
}
}
cin >> n;
vector<int> v;
v.push_back(0);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
v.push_back(a[i]);
v.push_back(b[i] + 1);
}
sort(all(v));
v.erase(unique(all(v)), v.end());
int m = v.size() - 1;
for (int i = 1; i < m; i++) {
for (int j = 0; j < n; j++) {
if (a[j] <= v[i] && b[j] >= v[i + 1] - 1) {
occ[i].push_back(j);
}
}
}
for (int i = 1; i < m; i++) {
ll t = 1;
for (int j = 0; j <= n; j++) {
c2[j] = t;
t = t * (v[i + 1] - v[i] - j) % MOD * bp(j + 1, MOD - 2) % MOD;
}
for (int j = 1; j <= occ[i].size(); j++) {
for (int h = 1; h <= j; h++) {
dp2[i][j] = (dp2[i][j] + c[j - 1][h - 1] * (ll)c2[h]) % MOD;
}
}
}
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 1; j < m; j++) {
f(dp[i][j], dp[i][j - 1]);
int g = lower_bound(all(occ[j]), i) - occ[j].begin();
for (int k = g; k < occ[j].size(); k++) {
dp[occ[j][k] + 1][j] = (dp[occ[j][k] + 1][j] + dp[i][j - 1] * (ll)dp2[j][k - g + 1]) % MOD;
}
}
}
int ans = 0;
for (int i = 1; i < m; i++) {
f(ans, dp[n][i]);
}
for (int i = 1; i < n; i++) {
f(ans, dp[i][m - 1]);
}
cout << ans;
/*cout << "\n" << slow() << "\n";*/
return 0;
}
Compilation message
boat.cpp:42:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning(disable : 4996)
boat.cpp: In function 'int main()':
boat.cpp:146:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 1; j <= occ[i].size(); j++) {
~~^~~~~~~~~~~~~~~~
boat.cpp:160:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = g; k < occ[j].size(); k++) {
~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
5368 KB |
Output is correct |
2 |
Correct |
85 ms |
5368 KB |
Output is correct |
3 |
Correct |
81 ms |
5368 KB |
Output is correct |
4 |
Correct |
79 ms |
5368 KB |
Output is correct |
5 |
Correct |
84 ms |
5336 KB |
Output is correct |
6 |
Correct |
85 ms |
5444 KB |
Output is correct |
7 |
Correct |
86 ms |
5308 KB |
Output is correct |
8 |
Correct |
89 ms |
5368 KB |
Output is correct |
9 |
Correct |
89 ms |
5432 KB |
Output is correct |
10 |
Correct |
91 ms |
5340 KB |
Output is correct |
11 |
Correct |
84 ms |
5340 KB |
Output is correct |
12 |
Correct |
86 ms |
5496 KB |
Output is correct |
13 |
Correct |
88 ms |
5396 KB |
Output is correct |
14 |
Correct |
88 ms |
5344 KB |
Output is correct |
15 |
Correct |
87 ms |
5368 KB |
Output is correct |
16 |
Correct |
19 ms |
3712 KB |
Output is correct |
17 |
Correct |
21 ms |
3684 KB |
Output is correct |
18 |
Correct |
20 ms |
3704 KB |
Output is correct |
19 |
Correct |
20 ms |
3712 KB |
Output is correct |
20 |
Correct |
19 ms |
3712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
5368 KB |
Output is correct |
2 |
Correct |
85 ms |
5368 KB |
Output is correct |
3 |
Correct |
81 ms |
5368 KB |
Output is correct |
4 |
Correct |
79 ms |
5368 KB |
Output is correct |
5 |
Correct |
84 ms |
5336 KB |
Output is correct |
6 |
Correct |
85 ms |
5444 KB |
Output is correct |
7 |
Correct |
86 ms |
5308 KB |
Output is correct |
8 |
Correct |
89 ms |
5368 KB |
Output is correct |
9 |
Correct |
89 ms |
5432 KB |
Output is correct |
10 |
Correct |
91 ms |
5340 KB |
Output is correct |
11 |
Correct |
84 ms |
5340 KB |
Output is correct |
12 |
Correct |
86 ms |
5496 KB |
Output is correct |
13 |
Correct |
88 ms |
5396 KB |
Output is correct |
14 |
Correct |
88 ms |
5344 KB |
Output is correct |
15 |
Correct |
87 ms |
5368 KB |
Output is correct |
16 |
Correct |
19 ms |
3712 KB |
Output is correct |
17 |
Correct |
21 ms |
3684 KB |
Output is correct |
18 |
Correct |
20 ms |
3704 KB |
Output is correct |
19 |
Correct |
20 ms |
3712 KB |
Output is correct |
20 |
Correct |
19 ms |
3712 KB |
Output is correct |
21 |
Correct |
351 ms |
6048 KB |
Output is correct |
22 |
Correct |
396 ms |
6152 KB |
Output is correct |
23 |
Correct |
337 ms |
5920 KB |
Output is correct |
24 |
Correct |
430 ms |
6008 KB |
Output is correct |
25 |
Correct |
311 ms |
5932 KB |
Output is correct |
26 |
Correct |
552 ms |
6324 KB |
Output is correct |
27 |
Correct |
564 ms |
6376 KB |
Output is correct |
28 |
Correct |
515 ms |
6304 KB |
Output is correct |
29 |
Correct |
606 ms |
6292 KB |
Output is correct |
30 |
Correct |
97 ms |
5384 KB |
Output is correct |
31 |
Correct |
81 ms |
5368 KB |
Output is correct |
32 |
Correct |
87 ms |
5340 KB |
Output is correct |
33 |
Correct |
87 ms |
5368 KB |
Output is correct |
34 |
Correct |
83 ms |
5344 KB |
Output is correct |
35 |
Correct |
87 ms |
5368 KB |
Output is correct |
36 |
Correct |
83 ms |
5368 KB |
Output is correct |
37 |
Correct |
87 ms |
5448 KB |
Output is correct |
38 |
Correct |
88 ms |
5360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
2276 KB |
Output is correct |
2 |
Correct |
10 ms |
2176 KB |
Output is correct |
3 |
Correct |
12 ms |
2176 KB |
Output is correct |
4 |
Correct |
10 ms |
2176 KB |
Output is correct |
5 |
Correct |
10 ms |
2176 KB |
Output is correct |
6 |
Correct |
11 ms |
2304 KB |
Output is correct |
7 |
Correct |
12 ms |
2176 KB |
Output is correct |
8 |
Correct |
11 ms |
2176 KB |
Output is correct |
9 |
Correct |
13 ms |
2312 KB |
Output is correct |
10 |
Correct |
11 ms |
2176 KB |
Output is correct |
11 |
Correct |
11 ms |
2148 KB |
Output is correct |
12 |
Correct |
11 ms |
2176 KB |
Output is correct |
13 |
Correct |
12 ms |
2236 KB |
Output is correct |
14 |
Correct |
9 ms |
2192 KB |
Output is correct |
15 |
Correct |
9 ms |
2148 KB |
Output is correct |
16 |
Correct |
8 ms |
2048 KB |
Output is correct |
17 |
Correct |
7 ms |
2048 KB |
Output is correct |
18 |
Correct |
8 ms |
2048 KB |
Output is correct |
19 |
Correct |
8 ms |
2048 KB |
Output is correct |
20 |
Correct |
6 ms |
1972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
5368 KB |
Output is correct |
2 |
Correct |
85 ms |
5368 KB |
Output is correct |
3 |
Correct |
81 ms |
5368 KB |
Output is correct |
4 |
Correct |
79 ms |
5368 KB |
Output is correct |
5 |
Correct |
84 ms |
5336 KB |
Output is correct |
6 |
Correct |
85 ms |
5444 KB |
Output is correct |
7 |
Correct |
86 ms |
5308 KB |
Output is correct |
8 |
Correct |
89 ms |
5368 KB |
Output is correct |
9 |
Correct |
89 ms |
5432 KB |
Output is correct |
10 |
Correct |
91 ms |
5340 KB |
Output is correct |
11 |
Correct |
84 ms |
5340 KB |
Output is correct |
12 |
Correct |
86 ms |
5496 KB |
Output is correct |
13 |
Correct |
88 ms |
5396 KB |
Output is correct |
14 |
Correct |
88 ms |
5344 KB |
Output is correct |
15 |
Correct |
87 ms |
5368 KB |
Output is correct |
16 |
Correct |
19 ms |
3712 KB |
Output is correct |
17 |
Correct |
21 ms |
3684 KB |
Output is correct |
18 |
Correct |
20 ms |
3704 KB |
Output is correct |
19 |
Correct |
20 ms |
3712 KB |
Output is correct |
20 |
Correct |
19 ms |
3712 KB |
Output is correct |
21 |
Correct |
351 ms |
6048 KB |
Output is correct |
22 |
Correct |
396 ms |
6152 KB |
Output is correct |
23 |
Correct |
337 ms |
5920 KB |
Output is correct |
24 |
Correct |
430 ms |
6008 KB |
Output is correct |
25 |
Correct |
311 ms |
5932 KB |
Output is correct |
26 |
Correct |
552 ms |
6324 KB |
Output is correct |
27 |
Correct |
564 ms |
6376 KB |
Output is correct |
28 |
Correct |
515 ms |
6304 KB |
Output is correct |
29 |
Correct |
606 ms |
6292 KB |
Output is correct |
30 |
Correct |
97 ms |
5384 KB |
Output is correct |
31 |
Correct |
81 ms |
5368 KB |
Output is correct |
32 |
Correct |
87 ms |
5340 KB |
Output is correct |
33 |
Correct |
87 ms |
5368 KB |
Output is correct |
34 |
Correct |
83 ms |
5344 KB |
Output is correct |
35 |
Correct |
87 ms |
5368 KB |
Output is correct |
36 |
Correct |
83 ms |
5368 KB |
Output is correct |
37 |
Correct |
87 ms |
5448 KB |
Output is correct |
38 |
Correct |
88 ms |
5360 KB |
Output is correct |
39 |
Correct |
10 ms |
2276 KB |
Output is correct |
40 |
Correct |
10 ms |
2176 KB |
Output is correct |
41 |
Correct |
12 ms |
2176 KB |
Output is correct |
42 |
Correct |
10 ms |
2176 KB |
Output is correct |
43 |
Correct |
10 ms |
2176 KB |
Output is correct |
44 |
Correct |
11 ms |
2304 KB |
Output is correct |
45 |
Correct |
12 ms |
2176 KB |
Output is correct |
46 |
Correct |
11 ms |
2176 KB |
Output is correct |
47 |
Correct |
13 ms |
2312 KB |
Output is correct |
48 |
Correct |
11 ms |
2176 KB |
Output is correct |
49 |
Correct |
11 ms |
2148 KB |
Output is correct |
50 |
Correct |
11 ms |
2176 KB |
Output is correct |
51 |
Correct |
12 ms |
2236 KB |
Output is correct |
52 |
Correct |
9 ms |
2192 KB |
Output is correct |
53 |
Correct |
9 ms |
2148 KB |
Output is correct |
54 |
Correct |
8 ms |
2048 KB |
Output is correct |
55 |
Correct |
7 ms |
2048 KB |
Output is correct |
56 |
Correct |
8 ms |
2048 KB |
Output is correct |
57 |
Correct |
8 ms |
2048 KB |
Output is correct |
58 |
Correct |
6 ms |
1972 KB |
Output is correct |
59 |
Correct |
471 ms |
6224 KB |
Output is correct |
60 |
Correct |
366 ms |
6284 KB |
Output is correct |
61 |
Correct |
383 ms |
6156 KB |
Output is correct |
62 |
Correct |
400 ms |
6432 KB |
Output is correct |
63 |
Correct |
349 ms |
6136 KB |
Output is correct |
64 |
Correct |
576 ms |
6796 KB |
Output is correct |
65 |
Correct |
651 ms |
6648 KB |
Output is correct |
66 |
Correct |
632 ms |
6776 KB |
Output is correct |
67 |
Correct |
625 ms |
6904 KB |
Output is correct |
68 |
Correct |
633 ms |
6776 KB |
Output is correct |
69 |
Correct |
317 ms |
6264 KB |
Output is correct |
70 |
Correct |
302 ms |
6148 KB |
Output is correct |
71 |
Correct |
323 ms |
6136 KB |
Output is correct |
72 |
Correct |
345 ms |
6056 KB |
Output is correct |
73 |
Correct |
366 ms |
6136 KB |
Output is correct |
74 |
Correct |
73 ms |
3960 KB |
Output is correct |
75 |
Correct |
85 ms |
4040 KB |
Output is correct |
76 |
Correct |
75 ms |
3836 KB |
Output is correct |
77 |
Correct |
85 ms |
3832 KB |
Output is correct |
78 |
Correct |
81 ms |
3960 KB |
Output is correct |