#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
vector<int> xx(1);
int f[505][1005], s[1005], g[1005][505], A[505], B[505], inv[1005];
int mp(int x, int r) {
int ret = 1;
while (r) {
if (r & 1) ret = 1ll * ret * x % mod;
x = 1ll * x * x % mod;
r >>= 1;
}
return ret;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int N; cin >> N;
for (int i = 1; i <= N; ++i) {
cin >> A[i] >> B[i]; B[i]++;
xx.push_back(A[i]);
xx.push_back(B[i]);
}
sort(xx.begin(), xx.end());
xx.erase(unique(xx.begin(), xx.end()), xx.end());
for (int i = 1; i <= N; ++i) inv[i] = mp(i, mod - 2);
for (int i = 1; i + 1 < xx.size(); ++i) g[i][0] = 1;
int ans = 0;
for (int i = 1; i <= N; ++i) {
f[i][0] = 1;
for (int j = 1; j + 1 < xx.size(); ++j) {
if (A[i] <= xx[j] && xx[j + 1] <= B[i]) {
long long n = xx[j + 1] - xx[j];
for (int k = i; k; --k) g[j][k] = (g[j][k] + g[j][k - 1] * (n + 1 - k) % mod * inv[k] % mod) % mod;
for (int k = 1; k <= i; ++k) f[i][j] = (f[i][j] + g[j][k]) % mod;
}
else {
f[i][j] = f[i - 1][j];
}
g[j][0] = (g[j - 1][0] + f[i][j - 1]) % mod;
}
}
for (int i = 1; i + 1 < xx.size(); ++i) ans = (ans + f[N][i]) % mod;
cout << ans;
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:29:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i + 1 < xx.size(); ++i) g[i][0] = 1;
~~~~~~^~~~~~~~~~~
boat.cpp:33:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 1; j + 1 < xx.size(); ++j) {
~~~~~~^~~~~~~~~~~
boat.cpp:45:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i + 1 < xx.size(); ++i) ans = (ans + f[N][i]) % mod;
~~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
4344 KB |
Output is correct |
2 |
Correct |
10 ms |
4344 KB |
Output is correct |
3 |
Correct |
11 ms |
4344 KB |
Output is correct |
4 |
Correct |
11 ms |
4344 KB |
Output is correct |
5 |
Correct |
10 ms |
4348 KB |
Output is correct |
6 |
Correct |
10 ms |
4344 KB |
Output is correct |
7 |
Correct |
10 ms |
4344 KB |
Output is correct |
8 |
Correct |
10 ms |
4344 KB |
Output is correct |
9 |
Correct |
10 ms |
4344 KB |
Output is correct |
10 |
Correct |
11 ms |
4344 KB |
Output is correct |
11 |
Correct |
10 ms |
4344 KB |
Output is correct |
12 |
Correct |
10 ms |
4344 KB |
Output is correct |
13 |
Correct |
11 ms |
4344 KB |
Output is correct |
14 |
Correct |
10 ms |
4344 KB |
Output is correct |
15 |
Correct |
10 ms |
4344 KB |
Output is correct |
16 |
Correct |
6 ms |
2680 KB |
Output is correct |
17 |
Correct |
6 ms |
2680 KB |
Output is correct |
18 |
Correct |
6 ms |
2680 KB |
Output is correct |
19 |
Correct |
6 ms |
2680 KB |
Output is correct |
20 |
Correct |
6 ms |
2680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
4344 KB |
Output is correct |
2 |
Correct |
10 ms |
4344 KB |
Output is correct |
3 |
Correct |
11 ms |
4344 KB |
Output is correct |
4 |
Correct |
11 ms |
4344 KB |
Output is correct |
5 |
Correct |
10 ms |
4348 KB |
Output is correct |
6 |
Correct |
10 ms |
4344 KB |
Output is correct |
7 |
Correct |
10 ms |
4344 KB |
Output is correct |
8 |
Correct |
10 ms |
4344 KB |
Output is correct |
9 |
Correct |
10 ms |
4344 KB |
Output is correct |
10 |
Correct |
11 ms |
4344 KB |
Output is correct |
11 |
Correct |
10 ms |
4344 KB |
Output is correct |
12 |
Correct |
10 ms |
4344 KB |
Output is correct |
13 |
Correct |
11 ms |
4344 KB |
Output is correct |
14 |
Correct |
10 ms |
4344 KB |
Output is correct |
15 |
Correct |
10 ms |
4344 KB |
Output is correct |
16 |
Correct |
6 ms |
2680 KB |
Output is correct |
17 |
Correct |
6 ms |
2680 KB |
Output is correct |
18 |
Correct |
6 ms |
2680 KB |
Output is correct |
19 |
Correct |
6 ms |
2680 KB |
Output is correct |
20 |
Correct |
6 ms |
2680 KB |
Output is correct |
21 |
Correct |
497 ms |
4212 KB |
Output is correct |
22 |
Correct |
477 ms |
4216 KB |
Output is correct |
23 |
Correct |
445 ms |
4180 KB |
Output is correct |
24 |
Correct |
475 ms |
4096 KB |
Output is correct |
25 |
Correct |
474 ms |
4176 KB |
Output is correct |
26 |
Correct |
676 ms |
4088 KB |
Output is correct |
27 |
Correct |
695 ms |
4300 KB |
Output is correct |
28 |
Correct |
671 ms |
4232 KB |
Output is correct |
29 |
Correct |
665 ms |
4168 KB |
Output is correct |
30 |
Correct |
14 ms |
4344 KB |
Output is correct |
31 |
Correct |
14 ms |
4344 KB |
Output is correct |
32 |
Correct |
14 ms |
4332 KB |
Output is correct |
33 |
Correct |
14 ms |
4344 KB |
Output is correct |
34 |
Correct |
13 ms |
4344 KB |
Output is correct |
35 |
Correct |
14 ms |
4344 KB |
Output is correct |
36 |
Correct |
13 ms |
4348 KB |
Output is correct |
37 |
Correct |
14 ms |
4344 KB |
Output is correct |
38 |
Correct |
14 ms |
4344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1144 KB |
Output is correct |
2 |
Correct |
6 ms |
1144 KB |
Output is correct |
3 |
Correct |
6 ms |
1144 KB |
Output is correct |
4 |
Correct |
7 ms |
1144 KB |
Output is correct |
5 |
Correct |
7 ms |
1144 KB |
Output is correct |
6 |
Correct |
9 ms |
1148 KB |
Output is correct |
7 |
Correct |
9 ms |
1144 KB |
Output is correct |
8 |
Correct |
9 ms |
1144 KB |
Output is correct |
9 |
Correct |
9 ms |
1144 KB |
Output is correct |
10 |
Correct |
9 ms |
1148 KB |
Output is correct |
11 |
Correct |
7 ms |
1272 KB |
Output is correct |
12 |
Correct |
6 ms |
1148 KB |
Output is correct |
13 |
Correct |
6 ms |
1144 KB |
Output is correct |
14 |
Correct |
6 ms |
1144 KB |
Output is correct |
15 |
Correct |
7 ms |
1148 KB |
Output is correct |
16 |
Correct |
5 ms |
1016 KB |
Output is correct |
17 |
Correct |
5 ms |
1016 KB |
Output is correct |
18 |
Correct |
5 ms |
1016 KB |
Output is correct |
19 |
Correct |
5 ms |
1016 KB |
Output is correct |
20 |
Correct |
5 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
4344 KB |
Output is correct |
2 |
Correct |
10 ms |
4344 KB |
Output is correct |
3 |
Correct |
11 ms |
4344 KB |
Output is correct |
4 |
Correct |
11 ms |
4344 KB |
Output is correct |
5 |
Correct |
10 ms |
4348 KB |
Output is correct |
6 |
Correct |
10 ms |
4344 KB |
Output is correct |
7 |
Correct |
10 ms |
4344 KB |
Output is correct |
8 |
Correct |
10 ms |
4344 KB |
Output is correct |
9 |
Correct |
10 ms |
4344 KB |
Output is correct |
10 |
Correct |
11 ms |
4344 KB |
Output is correct |
11 |
Correct |
10 ms |
4344 KB |
Output is correct |
12 |
Correct |
10 ms |
4344 KB |
Output is correct |
13 |
Correct |
11 ms |
4344 KB |
Output is correct |
14 |
Correct |
10 ms |
4344 KB |
Output is correct |
15 |
Correct |
10 ms |
4344 KB |
Output is correct |
16 |
Correct |
6 ms |
2680 KB |
Output is correct |
17 |
Correct |
6 ms |
2680 KB |
Output is correct |
18 |
Correct |
6 ms |
2680 KB |
Output is correct |
19 |
Correct |
6 ms |
2680 KB |
Output is correct |
20 |
Correct |
6 ms |
2680 KB |
Output is correct |
21 |
Correct |
497 ms |
4212 KB |
Output is correct |
22 |
Correct |
477 ms |
4216 KB |
Output is correct |
23 |
Correct |
445 ms |
4180 KB |
Output is correct |
24 |
Correct |
475 ms |
4096 KB |
Output is correct |
25 |
Correct |
474 ms |
4176 KB |
Output is correct |
26 |
Correct |
676 ms |
4088 KB |
Output is correct |
27 |
Correct |
695 ms |
4300 KB |
Output is correct |
28 |
Correct |
671 ms |
4232 KB |
Output is correct |
29 |
Correct |
665 ms |
4168 KB |
Output is correct |
30 |
Correct |
14 ms |
4344 KB |
Output is correct |
31 |
Correct |
14 ms |
4344 KB |
Output is correct |
32 |
Correct |
14 ms |
4332 KB |
Output is correct |
33 |
Correct |
14 ms |
4344 KB |
Output is correct |
34 |
Correct |
13 ms |
4344 KB |
Output is correct |
35 |
Correct |
14 ms |
4344 KB |
Output is correct |
36 |
Correct |
13 ms |
4348 KB |
Output is correct |
37 |
Correct |
14 ms |
4344 KB |
Output is correct |
38 |
Correct |
14 ms |
4344 KB |
Output is correct |
39 |
Correct |
9 ms |
1144 KB |
Output is correct |
40 |
Correct |
6 ms |
1144 KB |
Output is correct |
41 |
Correct |
6 ms |
1144 KB |
Output is correct |
42 |
Correct |
7 ms |
1144 KB |
Output is correct |
43 |
Correct |
7 ms |
1144 KB |
Output is correct |
44 |
Correct |
9 ms |
1148 KB |
Output is correct |
45 |
Correct |
9 ms |
1144 KB |
Output is correct |
46 |
Correct |
9 ms |
1144 KB |
Output is correct |
47 |
Correct |
9 ms |
1144 KB |
Output is correct |
48 |
Correct |
9 ms |
1148 KB |
Output is correct |
49 |
Correct |
7 ms |
1272 KB |
Output is correct |
50 |
Correct |
6 ms |
1148 KB |
Output is correct |
51 |
Correct |
6 ms |
1144 KB |
Output is correct |
52 |
Correct |
6 ms |
1144 KB |
Output is correct |
53 |
Correct |
7 ms |
1148 KB |
Output is correct |
54 |
Correct |
5 ms |
1016 KB |
Output is correct |
55 |
Correct |
5 ms |
1016 KB |
Output is correct |
56 |
Correct |
5 ms |
1016 KB |
Output is correct |
57 |
Correct |
5 ms |
1016 KB |
Output is correct |
58 |
Correct |
5 ms |
888 KB |
Output is correct |
59 |
Correct |
531 ms |
4356 KB |
Output is correct |
60 |
Correct |
508 ms |
4304 KB |
Output is correct |
61 |
Correct |
479 ms |
4392 KB |
Output is correct |
62 |
Correct |
527 ms |
4540 KB |
Output is correct |
63 |
Correct |
520 ms |
4360 KB |
Output is correct |
64 |
Correct |
769 ms |
4276 KB |
Output is correct |
65 |
Correct |
771 ms |
4424 KB |
Output is correct |
66 |
Correct |
768 ms |
4472 KB |
Output is correct |
67 |
Correct |
768 ms |
4588 KB |
Output is correct |
68 |
Correct |
767 ms |
4392 KB |
Output is correct |
69 |
Correct |
409 ms |
4356 KB |
Output is correct |
70 |
Correct |
399 ms |
4344 KB |
Output is correct |
71 |
Correct |
395 ms |
4444 KB |
Output is correct |
72 |
Correct |
413 ms |
4424 KB |
Output is correct |
73 |
Correct |
423 ms |
4344 KB |
Output is correct |
74 |
Correct |
106 ms |
2680 KB |
Output is correct |
75 |
Correct |
101 ms |
2680 KB |
Output is correct |
76 |
Correct |
105 ms |
2660 KB |
Output is correct |
77 |
Correct |
105 ms |
2780 KB |
Output is correct |
78 |
Correct |
107 ms |
2652 KB |
Output is correct |