#include <bits/stdc++.h>
#define ll long long
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define fs first
#define se second
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define pb push_back
#define SZ(v) (ll)v.size()
#define ALL(v) v.begin(),v.end()
using namespace std;
mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }
const int N = 5e2 + 7;
const int Mod = 1e9 + 7;
const int INF = 1e9;
const ll BASE = 137;
const int szBL = 320;
int n, m;
pii a[N];
int dp[N][N * 2], f[N][N * 2], com[N * 2][N], combi[N][N], inv[N];
inline void add (int &a, int b) { a = a + b; if (a >= Mod) a = a - Mod; }
bool cover (pii A, pii B) {
return A.fs <= B.fs && A.se >= B.se;
}
void solution () {
cin >> n;
vector<pii> vec, seg = {MP(0, 0)};
rep (i, 1, n) {
cin >> a[i].fs >> a[i].se;
vec.pb({a[i].fs, 0}), vec.pb({a[i].se, 1});
}
sort (ALL(vec));
vec.resize(unique(ALL(vec)) - vec.begin());
rep (i, 0, SZ(vec) - 2) {
if (vec[i].se == vec[i + 1].se) {
if (vec[i].se == 1) seg.pb({vec[i].fs + 1, vec[i + 1].fs});
else seg.pb({vec[i].fs, vec[i + 1].fs - 1});
}
else {
if (vec[i].se == 0) seg.pb({vec[i].fs, vec[i + 1].fs});
else seg.pb({vec[i].fs + 1, vec[i +1 ].fs - 1});
}
}
inv[1] = 1;
rep (i, 2, n + 1) inv[i] = (Mod - (ll)(Mod/i) * inv[Mod % i] % Mod + Mod) % Mod;
m = SZ(seg) - 1;
rep (i, 0, m) {
int Len = seg[i].se - seg[i].fs + 1;
com[i][0] = 1;
rep (j, 1, n + 1) {
if (j > Len) com[i][j] = 0;
else com[i][j] = 1LL * com[i][j - 1] * (Len - j + 1) % Mod * inv[j] % Mod;
}
}
rep (i, 0, n) {
rep (j, 0, i) {
if (j == i || j == 0) combi[i][j] = 1;
else combi[i][j] = (combi[i - 1][j - 1] + combi[i - 1][j]) % Mod;
}
}
rep (i, 0, n) {
rep (j, 0, m) {
rep (k, 0, i) {
add(f[i][j], 1LL * combi[i][k] * com[j][k + 1] % Mod);
}
}
}
rep (j, 0, m) dp[0][j] = 1;
rep (i, 1, n) {
dp[i][0] = 1;
rep (j, 1, m) {
dp[i][j] = dp[i][j - 1];
int num = 0;
reb (k, i, 1) {
if (cover(a[k], seg[j])) {
add(dp[i][j], 1LL * dp[k - 1][j - 1] * f[num][j] % Mod);
++num;
}
}
// cout << i <<" "<<seg[j].fs<<","<<seg[j].se<<": "<<dp[i][j] <<"\n";
}
}
cout << (dp[n][m] - 1 + Mod) % Mod <<"\n";
}
#define file(name) freopen(name".inp","r",stdin); \
freopen(name".out","w",stdout);
int main () {
// file("c");
ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
int num_Test = 1;
// cin >> num_Test;
while (num_Test--)
solution();
}
/*
no bug challenge +4
mình có muốn dùng mảng này không?
4 5
1 3
4 1
1 2
3 2
2 1
return->break
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
365 ms |
7396 KB |
Output is correct |
2 |
Correct |
380 ms |
7252 KB |
Output is correct |
3 |
Correct |
371 ms |
7252 KB |
Output is correct |
4 |
Correct |
385 ms |
7248 KB |
Output is correct |
5 |
Correct |
361 ms |
7248 KB |
Output is correct |
6 |
Correct |
350 ms |
7320 KB |
Output is correct |
7 |
Correct |
348 ms |
7324 KB |
Output is correct |
8 |
Correct |
356 ms |
7256 KB |
Output is correct |
9 |
Correct |
358 ms |
7252 KB |
Output is correct |
10 |
Correct |
349 ms |
7248 KB |
Output is correct |
11 |
Correct |
348 ms |
7316 KB |
Output is correct |
12 |
Correct |
357 ms |
7260 KB |
Output is correct |
13 |
Correct |
359 ms |
7252 KB |
Output is correct |
14 |
Correct |
348 ms |
7304 KB |
Output is correct |
15 |
Correct |
354 ms |
7248 KB |
Output is correct |
16 |
Correct |
67 ms |
5712 KB |
Output is correct |
17 |
Correct |
75 ms |
5712 KB |
Output is correct |
18 |
Correct |
71 ms |
5716 KB |
Output is correct |
19 |
Correct |
73 ms |
5716 KB |
Output is correct |
20 |
Correct |
69 ms |
5656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
365 ms |
7396 KB |
Output is correct |
2 |
Correct |
380 ms |
7252 KB |
Output is correct |
3 |
Correct |
371 ms |
7252 KB |
Output is correct |
4 |
Correct |
385 ms |
7248 KB |
Output is correct |
5 |
Correct |
361 ms |
7248 KB |
Output is correct |
6 |
Correct |
350 ms |
7320 KB |
Output is correct |
7 |
Correct |
348 ms |
7324 KB |
Output is correct |
8 |
Correct |
356 ms |
7256 KB |
Output is correct |
9 |
Correct |
358 ms |
7252 KB |
Output is correct |
10 |
Correct |
349 ms |
7248 KB |
Output is correct |
11 |
Correct |
348 ms |
7316 KB |
Output is correct |
12 |
Correct |
357 ms |
7260 KB |
Output is correct |
13 |
Correct |
359 ms |
7252 KB |
Output is correct |
14 |
Correct |
348 ms |
7304 KB |
Output is correct |
15 |
Correct |
354 ms |
7248 KB |
Output is correct |
16 |
Correct |
67 ms |
5712 KB |
Output is correct |
17 |
Correct |
75 ms |
5712 KB |
Output is correct |
18 |
Correct |
71 ms |
5716 KB |
Output is correct |
19 |
Correct |
73 ms |
5716 KB |
Output is correct |
20 |
Correct |
69 ms |
5656 KB |
Output is correct |
21 |
Correct |
420 ms |
7256 KB |
Output is correct |
22 |
Correct |
422 ms |
7248 KB |
Output is correct |
23 |
Correct |
405 ms |
7248 KB |
Output is correct |
24 |
Correct |
412 ms |
7248 KB |
Output is correct |
25 |
Correct |
418 ms |
7240 KB |
Output is correct |
26 |
Correct |
468 ms |
6972 KB |
Output is correct |
27 |
Correct |
497 ms |
6996 KB |
Output is correct |
28 |
Correct |
465 ms |
6996 KB |
Output is correct |
29 |
Correct |
472 ms |
6992 KB |
Output is correct |
30 |
Correct |
352 ms |
7296 KB |
Output is correct |
31 |
Correct |
350 ms |
7412 KB |
Output is correct |
32 |
Correct |
347 ms |
7252 KB |
Output is correct |
33 |
Correct |
354 ms |
7248 KB |
Output is correct |
34 |
Correct |
350 ms |
7252 KB |
Output is correct |
35 |
Correct |
370 ms |
7324 KB |
Output is correct |
36 |
Correct |
367 ms |
7252 KB |
Output is correct |
37 |
Correct |
382 ms |
7312 KB |
Output is correct |
38 |
Correct |
364 ms |
7252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1884 KB |
Output is correct |
2 |
Correct |
4 ms |
1880 KB |
Output is correct |
3 |
Correct |
5 ms |
1884 KB |
Output is correct |
4 |
Correct |
5 ms |
1884 KB |
Output is correct |
5 |
Correct |
5 ms |
1884 KB |
Output is correct |
6 |
Correct |
5 ms |
1676 KB |
Output is correct |
7 |
Correct |
5 ms |
1884 KB |
Output is correct |
8 |
Correct |
5 ms |
1880 KB |
Output is correct |
9 |
Correct |
5 ms |
1884 KB |
Output is correct |
10 |
Correct |
5 ms |
1884 KB |
Output is correct |
11 |
Correct |
5 ms |
1884 KB |
Output is correct |
12 |
Correct |
5 ms |
1884 KB |
Output is correct |
13 |
Correct |
5 ms |
1892 KB |
Output is correct |
14 |
Correct |
5 ms |
1828 KB |
Output is correct |
15 |
Correct |
5 ms |
1660 KB |
Output is correct |
16 |
Correct |
3 ms |
1628 KB |
Output is correct |
17 |
Correct |
4 ms |
1628 KB |
Output is correct |
18 |
Correct |
3 ms |
1628 KB |
Output is correct |
19 |
Correct |
3 ms |
1628 KB |
Output is correct |
20 |
Correct |
3 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
365 ms |
7396 KB |
Output is correct |
2 |
Correct |
380 ms |
7252 KB |
Output is correct |
3 |
Correct |
371 ms |
7252 KB |
Output is correct |
4 |
Correct |
385 ms |
7248 KB |
Output is correct |
5 |
Correct |
361 ms |
7248 KB |
Output is correct |
6 |
Correct |
350 ms |
7320 KB |
Output is correct |
7 |
Correct |
348 ms |
7324 KB |
Output is correct |
8 |
Correct |
356 ms |
7256 KB |
Output is correct |
9 |
Correct |
358 ms |
7252 KB |
Output is correct |
10 |
Correct |
349 ms |
7248 KB |
Output is correct |
11 |
Correct |
348 ms |
7316 KB |
Output is correct |
12 |
Correct |
357 ms |
7260 KB |
Output is correct |
13 |
Correct |
359 ms |
7252 KB |
Output is correct |
14 |
Correct |
348 ms |
7304 KB |
Output is correct |
15 |
Correct |
354 ms |
7248 KB |
Output is correct |
16 |
Correct |
67 ms |
5712 KB |
Output is correct |
17 |
Correct |
75 ms |
5712 KB |
Output is correct |
18 |
Correct |
71 ms |
5716 KB |
Output is correct |
19 |
Correct |
73 ms |
5716 KB |
Output is correct |
20 |
Correct |
69 ms |
5656 KB |
Output is correct |
21 |
Correct |
420 ms |
7256 KB |
Output is correct |
22 |
Correct |
422 ms |
7248 KB |
Output is correct |
23 |
Correct |
405 ms |
7248 KB |
Output is correct |
24 |
Correct |
412 ms |
7248 KB |
Output is correct |
25 |
Correct |
418 ms |
7240 KB |
Output is correct |
26 |
Correct |
468 ms |
6972 KB |
Output is correct |
27 |
Correct |
497 ms |
6996 KB |
Output is correct |
28 |
Correct |
465 ms |
6996 KB |
Output is correct |
29 |
Correct |
472 ms |
6992 KB |
Output is correct |
30 |
Correct |
352 ms |
7296 KB |
Output is correct |
31 |
Correct |
350 ms |
7412 KB |
Output is correct |
32 |
Correct |
347 ms |
7252 KB |
Output is correct |
33 |
Correct |
354 ms |
7248 KB |
Output is correct |
34 |
Correct |
350 ms |
7252 KB |
Output is correct |
35 |
Correct |
370 ms |
7324 KB |
Output is correct |
36 |
Correct |
367 ms |
7252 KB |
Output is correct |
37 |
Correct |
382 ms |
7312 KB |
Output is correct |
38 |
Correct |
364 ms |
7252 KB |
Output is correct |
39 |
Correct |
5 ms |
1884 KB |
Output is correct |
40 |
Correct |
4 ms |
1880 KB |
Output is correct |
41 |
Correct |
5 ms |
1884 KB |
Output is correct |
42 |
Correct |
5 ms |
1884 KB |
Output is correct |
43 |
Correct |
5 ms |
1884 KB |
Output is correct |
44 |
Correct |
5 ms |
1676 KB |
Output is correct |
45 |
Correct |
5 ms |
1884 KB |
Output is correct |
46 |
Correct |
5 ms |
1880 KB |
Output is correct |
47 |
Correct |
5 ms |
1884 KB |
Output is correct |
48 |
Correct |
5 ms |
1884 KB |
Output is correct |
49 |
Correct |
5 ms |
1884 KB |
Output is correct |
50 |
Correct |
5 ms |
1884 KB |
Output is correct |
51 |
Correct |
5 ms |
1892 KB |
Output is correct |
52 |
Correct |
5 ms |
1828 KB |
Output is correct |
53 |
Correct |
5 ms |
1660 KB |
Output is correct |
54 |
Correct |
3 ms |
1628 KB |
Output is correct |
55 |
Correct |
4 ms |
1628 KB |
Output is correct |
56 |
Correct |
3 ms |
1628 KB |
Output is correct |
57 |
Correct |
3 ms |
1628 KB |
Output is correct |
58 |
Correct |
3 ms |
1628 KB |
Output is correct |
59 |
Correct |
449 ms |
7392 KB |
Output is correct |
60 |
Correct |
440 ms |
7248 KB |
Output is correct |
61 |
Correct |
450 ms |
7240 KB |
Output is correct |
62 |
Correct |
453 ms |
7408 KB |
Output is correct |
63 |
Correct |
448 ms |
7236 KB |
Output is correct |
64 |
Correct |
542 ms |
7376 KB |
Output is correct |
65 |
Correct |
539 ms |
7252 KB |
Output is correct |
66 |
Correct |
542 ms |
7248 KB |
Output is correct |
67 |
Correct |
534 ms |
7252 KB |
Output is correct |
68 |
Correct |
537 ms |
7440 KB |
Output is correct |
69 |
Correct |
473 ms |
7372 KB |
Output is correct |
70 |
Correct |
474 ms |
7364 KB |
Output is correct |
71 |
Correct |
472 ms |
7252 KB |
Output is correct |
72 |
Correct |
487 ms |
7248 KB |
Output is correct |
73 |
Correct |
487 ms |
7252 KB |
Output is correct |
74 |
Correct |
85 ms |
5636 KB |
Output is correct |
75 |
Correct |
91 ms |
5732 KB |
Output is correct |
76 |
Correct |
93 ms |
5716 KB |
Output is correct |
77 |
Correct |
92 ms |
5584 KB |
Output is correct |
78 |
Correct |
85 ms |
5716 KB |
Output is correct |