#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rep(i, s, e) for (int i = s; i < e; i++)
// START for segment tree
#define params int p, int L, int R
#define housekeep int mid = (L + R) >> 1, left = p << 1, right = left | 1
// END
#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif
#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
advance(it, -n);
return it;
}
template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
advance(it, n);
return it;
}
#endif
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ldouble;
const double EPS = 1e-9;
const double PI = 3.141592653589793238462;
template<typename T>
inline T sq(T a) { return a * a; }
//#ifdef LOCAL_MACHINE
//#endif
const int MAXN = 505;
const int MOD = 1e9 + 7;
inline int mul_mod(int a, int b) {
return a * 1LL * b % MOD;
}
inline void add_mod(int &a, int b) {
a += b;
if (a >= MOD) a -= MOD;
}
int mpow(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1)
res = mul_mod(res, a);
a = mul_mod(a, a);
b >>= 1;
}
return res;
}
int a[MAXN], b[MAXN];
int s[2 * MAXN];
int nCr[2 * MAXN][MAXN];
int dp[2][2 * MAXN][MAXN][2];
int main() {
//freopen("", "r", stdin);
//freopen("", "w", stdout);
int n;
scanf("%d", &n);
vi pts = {0};
for (int i = 1; i <= n; i++) {
scanf("%d %d", &a[i], &b[i]);
pts.pb(a[i]);
pts.pb(b[i]);
}
sort(all(pts));
pts.resize(unique(all(pts)) - pts.begin());
int m = (int)pts.size() - 1;
for (int j = 1; j <= m; j++)
s[j] = pts[j] - pts[j - 1] - 1;
for (int j = 0; j <= m; j++) {
nCr[j][0] = 1;
for (int k = 1; k <= n; k++) {
if (k > s[j]) {
nCr[j][k] = 0;
} else {
nCr[j][k] = mul_mod(
mul_mod(s[j] - k + 1, mpow(k, MOD - 2)),
nCr[j][k - 1]);
}
}
}
for (int j = 0; j <= m; j++)
dp[0 & 1][j][0][0] = 1;
for (int i = 1; i <= n; i++) {
dp[i & 1][0][0][0] = 1;
for (int j = 1; j <= m + (i == n); j++) {
dp[i & 1][j][0][0] = 0;
for (int z = 0; z <= i; z++) {
add_mod(dp[i & 1][j][0][0], mul_mod(dp[i & 1][j - 1][z][0], nCr[j - 1][z]));
if (z > 0)
add_mod(dp[i & 1][j][0][0], mul_mod(dp[i & 1][j - 1][z][1], nCr[j - 1][z - 1]));
}
if (j == m + 1) continue;
for (int k = 1; k <= i; k++) {
for (int f = 0; f <= 1; f++) {
dp[i & 1][j][k][f] = 0;
add_mod(dp[i & 1][j][k][f], dp[(i - 1) & 1][j][k][f]);
if (f == 1 && a[i] <= pts[j] && b[i] >= pts[j])
add_mod(dp[i & 1][j][k][f], dp[(i - 1) & 1][j][k - 1][0]);
else if (f == 0 && a[i] < pts[j] && b[i] >= pts[j])
add_mod(dp[i & 1][j][k][f], dp[(i - 1) & 1][j][k - 1][f]);
}
}
}
}
printf("%d\n", (dp[n & 1][m + 1][0][0] + MOD - 1) % MOD);
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:89:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
boat.cpp:92:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &a[i], &b[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
887 ms |
5372 KB |
Output is correct |
2 |
Correct |
728 ms |
5480 KB |
Output is correct |
3 |
Correct |
712 ms |
5604 KB |
Output is correct |
4 |
Correct |
817 ms |
5604 KB |
Output is correct |
5 |
Correct |
848 ms |
5720 KB |
Output is correct |
6 |
Correct |
719 ms |
5772 KB |
Output is correct |
7 |
Correct |
675 ms |
5776 KB |
Output is correct |
8 |
Correct |
714 ms |
5792 KB |
Output is correct |
9 |
Correct |
721 ms |
5792 KB |
Output is correct |
10 |
Correct |
820 ms |
5980 KB |
Output is correct |
11 |
Correct |
715 ms |
5980 KB |
Output is correct |
12 |
Correct |
682 ms |
5980 KB |
Output is correct |
13 |
Correct |
686 ms |
5980 KB |
Output is correct |
14 |
Correct |
781 ms |
5980 KB |
Output is correct |
15 |
Correct |
673 ms |
5980 KB |
Output is correct |
16 |
Correct |
120 ms |
5980 KB |
Output is correct |
17 |
Correct |
132 ms |
5980 KB |
Output is correct |
18 |
Correct |
124 ms |
5980 KB |
Output is correct |
19 |
Correct |
130 ms |
5980 KB |
Output is correct |
20 |
Correct |
125 ms |
5980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
887 ms |
5372 KB |
Output is correct |
2 |
Correct |
728 ms |
5480 KB |
Output is correct |
3 |
Correct |
712 ms |
5604 KB |
Output is correct |
4 |
Correct |
817 ms |
5604 KB |
Output is correct |
5 |
Correct |
848 ms |
5720 KB |
Output is correct |
6 |
Correct |
719 ms |
5772 KB |
Output is correct |
7 |
Correct |
675 ms |
5776 KB |
Output is correct |
8 |
Correct |
714 ms |
5792 KB |
Output is correct |
9 |
Correct |
721 ms |
5792 KB |
Output is correct |
10 |
Correct |
820 ms |
5980 KB |
Output is correct |
11 |
Correct |
715 ms |
5980 KB |
Output is correct |
12 |
Correct |
682 ms |
5980 KB |
Output is correct |
13 |
Correct |
686 ms |
5980 KB |
Output is correct |
14 |
Correct |
781 ms |
5980 KB |
Output is correct |
15 |
Correct |
673 ms |
5980 KB |
Output is correct |
16 |
Correct |
120 ms |
5980 KB |
Output is correct |
17 |
Correct |
132 ms |
5980 KB |
Output is correct |
18 |
Correct |
124 ms |
5980 KB |
Output is correct |
19 |
Correct |
130 ms |
5980 KB |
Output is correct |
20 |
Correct |
125 ms |
5980 KB |
Output is correct |
21 |
Correct |
1228 ms |
10124 KB |
Output is correct |
22 |
Correct |
1219 ms |
10124 KB |
Output is correct |
23 |
Correct |
1194 ms |
10124 KB |
Output is correct |
24 |
Correct |
1213 ms |
10140 KB |
Output is correct |
25 |
Correct |
1207 ms |
10140 KB |
Output is correct |
26 |
Correct |
1232 ms |
10140 KB |
Output is correct |
27 |
Correct |
1219 ms |
10140 KB |
Output is correct |
28 |
Correct |
1212 ms |
10140 KB |
Output is correct |
29 |
Correct |
1382 ms |
10140 KB |
Output is correct |
30 |
Correct |
1546 ms |
10516 KB |
Output is correct |
31 |
Correct |
1482 ms |
10516 KB |
Output is correct |
32 |
Correct |
1384 ms |
10596 KB |
Output is correct |
33 |
Correct |
1312 ms |
10596 KB |
Output is correct |
34 |
Correct |
1610 ms |
10596 KB |
Output is correct |
35 |
Correct |
681 ms |
10596 KB |
Output is correct |
36 |
Correct |
672 ms |
10596 KB |
Output is correct |
37 |
Correct |
827 ms |
10596 KB |
Output is correct |
38 |
Correct |
802 ms |
10596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
10596 KB |
Output is correct |
2 |
Correct |
19 ms |
10596 KB |
Output is correct |
3 |
Correct |
20 ms |
10596 KB |
Output is correct |
4 |
Correct |
21 ms |
10596 KB |
Output is correct |
5 |
Correct |
19 ms |
10596 KB |
Output is correct |
6 |
Correct |
19 ms |
10596 KB |
Output is correct |
7 |
Correct |
20 ms |
10596 KB |
Output is correct |
8 |
Correct |
19 ms |
10596 KB |
Output is correct |
9 |
Correct |
19 ms |
10596 KB |
Output is correct |
10 |
Correct |
20 ms |
10596 KB |
Output is correct |
11 |
Correct |
18 ms |
10596 KB |
Output is correct |
12 |
Correct |
19 ms |
10596 KB |
Output is correct |
13 |
Correct |
18 ms |
10596 KB |
Output is correct |
14 |
Correct |
26 ms |
10596 KB |
Output is correct |
15 |
Correct |
19 ms |
10596 KB |
Output is correct |
16 |
Correct |
12 ms |
10596 KB |
Output is correct |
17 |
Correct |
10 ms |
10596 KB |
Output is correct |
18 |
Correct |
10 ms |
10596 KB |
Output is correct |
19 |
Correct |
14 ms |
10596 KB |
Output is correct |
20 |
Correct |
10 ms |
10596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
887 ms |
5372 KB |
Output is correct |
2 |
Correct |
728 ms |
5480 KB |
Output is correct |
3 |
Correct |
712 ms |
5604 KB |
Output is correct |
4 |
Correct |
817 ms |
5604 KB |
Output is correct |
5 |
Correct |
848 ms |
5720 KB |
Output is correct |
6 |
Correct |
719 ms |
5772 KB |
Output is correct |
7 |
Correct |
675 ms |
5776 KB |
Output is correct |
8 |
Correct |
714 ms |
5792 KB |
Output is correct |
9 |
Correct |
721 ms |
5792 KB |
Output is correct |
10 |
Correct |
820 ms |
5980 KB |
Output is correct |
11 |
Correct |
715 ms |
5980 KB |
Output is correct |
12 |
Correct |
682 ms |
5980 KB |
Output is correct |
13 |
Correct |
686 ms |
5980 KB |
Output is correct |
14 |
Correct |
781 ms |
5980 KB |
Output is correct |
15 |
Correct |
673 ms |
5980 KB |
Output is correct |
16 |
Correct |
120 ms |
5980 KB |
Output is correct |
17 |
Correct |
132 ms |
5980 KB |
Output is correct |
18 |
Correct |
124 ms |
5980 KB |
Output is correct |
19 |
Correct |
130 ms |
5980 KB |
Output is correct |
20 |
Correct |
125 ms |
5980 KB |
Output is correct |
21 |
Correct |
1228 ms |
10124 KB |
Output is correct |
22 |
Correct |
1219 ms |
10124 KB |
Output is correct |
23 |
Correct |
1194 ms |
10124 KB |
Output is correct |
24 |
Correct |
1213 ms |
10140 KB |
Output is correct |
25 |
Correct |
1207 ms |
10140 KB |
Output is correct |
26 |
Correct |
1232 ms |
10140 KB |
Output is correct |
27 |
Correct |
1219 ms |
10140 KB |
Output is correct |
28 |
Correct |
1212 ms |
10140 KB |
Output is correct |
29 |
Correct |
1382 ms |
10140 KB |
Output is correct |
30 |
Correct |
1546 ms |
10516 KB |
Output is correct |
31 |
Correct |
1482 ms |
10516 KB |
Output is correct |
32 |
Correct |
1384 ms |
10596 KB |
Output is correct |
33 |
Correct |
1312 ms |
10596 KB |
Output is correct |
34 |
Correct |
1610 ms |
10596 KB |
Output is correct |
35 |
Correct |
681 ms |
10596 KB |
Output is correct |
36 |
Correct |
672 ms |
10596 KB |
Output is correct |
37 |
Correct |
827 ms |
10596 KB |
Output is correct |
38 |
Correct |
802 ms |
10596 KB |
Output is correct |
39 |
Correct |
25 ms |
10596 KB |
Output is correct |
40 |
Correct |
19 ms |
10596 KB |
Output is correct |
41 |
Correct |
20 ms |
10596 KB |
Output is correct |
42 |
Correct |
21 ms |
10596 KB |
Output is correct |
43 |
Correct |
19 ms |
10596 KB |
Output is correct |
44 |
Correct |
19 ms |
10596 KB |
Output is correct |
45 |
Correct |
20 ms |
10596 KB |
Output is correct |
46 |
Correct |
19 ms |
10596 KB |
Output is correct |
47 |
Correct |
19 ms |
10596 KB |
Output is correct |
48 |
Correct |
20 ms |
10596 KB |
Output is correct |
49 |
Correct |
18 ms |
10596 KB |
Output is correct |
50 |
Correct |
19 ms |
10596 KB |
Output is correct |
51 |
Correct |
18 ms |
10596 KB |
Output is correct |
52 |
Correct |
26 ms |
10596 KB |
Output is correct |
53 |
Correct |
19 ms |
10596 KB |
Output is correct |
54 |
Correct |
12 ms |
10596 KB |
Output is correct |
55 |
Correct |
10 ms |
10596 KB |
Output is correct |
56 |
Correct |
10 ms |
10596 KB |
Output is correct |
57 |
Correct |
14 ms |
10596 KB |
Output is correct |
58 |
Correct |
10 ms |
10596 KB |
Output is correct |
59 |
Correct |
1543 ms |
11192 KB |
Output is correct |
60 |
Correct |
1677 ms |
11196 KB |
Output is correct |
61 |
Correct |
1478 ms |
11216 KB |
Output is correct |
62 |
Correct |
1658 ms |
11276 KB |
Output is correct |
63 |
Correct |
1511 ms |
11276 KB |
Output is correct |
64 |
Correct |
1720 ms |
11356 KB |
Output is correct |
65 |
Correct |
1683 ms |
11392 KB |
Output is correct |
66 |
Correct |
1915 ms |
11392 KB |
Output is correct |
67 |
Correct |
1792 ms |
11392 KB |
Output is correct |
68 |
Correct |
1813 ms |
11392 KB |
Output is correct |
69 |
Correct |
1647 ms |
11392 KB |
Output is correct |
70 |
Correct |
1454 ms |
11452 KB |
Output is correct |
71 |
Correct |
1605 ms |
11452 KB |
Output is correct |
72 |
Correct |
1656 ms |
11452 KB |
Output is correct |
73 |
Correct |
1451 ms |
11452 KB |
Output is correct |
74 |
Correct |
145 ms |
11452 KB |
Output is correct |
75 |
Correct |
163 ms |
11452 KB |
Output is correct |
76 |
Correct |
149 ms |
11452 KB |
Output is correct |
77 |
Correct |
147 ms |
11452 KB |
Output is correct |
78 |
Correct |
146 ms |
11452 KB |
Output is correct |