#include<bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1007, MOD = 1000 * 1000 * 1000 + 7;
int mod(ll n) {
if (n < MOD)
return n;
else if (n < 2 * MOD)
return n - MOD;
else
return n % MOD;
}
int fp(int a, int p) {
ll ans = 1, c = a;
for (int i = 0; (1ll << i) <= p; ++i) {
if ((p >> i) & 1) ans = mod(ans * c);
c = mod(c * c);
}
return ans;
}
void addmod(int &a, int b) {
a = mod(a + b);
}
int f[N], inv[N];
int n, l[N], r[N], dp[N][N], mem[N][N], cur[N], pref[N], lmao[N];
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
f[0] = inv[0] = 1;
for (int i = 1; i < N; ++i) {
f[i] = mod((ll)f[i - 1] * i);
inv[i] = fp(f[i], MOD - 2);
}
for (int i = 0; i < N; ++i)
mem[i][0] = 1;
for (int i = 1; i < N; ++i)
for (int j = 1; j < N; ++j)
mem[i][j] = mod(mem[i - 1][j] + mem[i - 1][j - 1]);
cin >> n;
vector <int> c;
for (int i = 1; i <= n; ++i) {
cin >> l[i] >> r[i];
c.app(l[i]); c.app(r[i] + 1);
}
sort(all(c));
c.resize(unique(all(c)) - c.begin());
dp[0][0] = 1;
for (int i = 0; i + 1 < (int)c.size(); ++i) {
cur[0] = 1;
ll t = 1;
for (int j = 1; j <= n; ++j) {
t = mod(t * (c[i + 1] - c[i] - j + 1));
cur[j] = mod(t * inv[j]);
}
for (int j = 1; j <= n; ++j)
pref[j] = pref[j - 1] + (l[j] <= c[i] && c[i + 1] - 1 <= r[j]);
for (int mx = 1; mx <= n; ++mx) {
lmao[mx] = 0;
for (int cnt = 1; cnt <= mx; ++cnt)
addmod(lmao[mx], mod((ll)mem[mx - 1][cnt - 1] * cur[cnt]));
}
for (int j = 0; j <= n; ++j) {
addmod(dp[i + 1][j], dp[i][j]);
for (int k = j + 1; k <= n; ++k) {
if (l[k] <= c[i] && c[i + 1] - 1 <= r[k]) {
int mx = pref[k] - pref[j];
addmod(dp[i + 1][k], mod((ll)dp[i][j] * lmao[mx]));
}
}
}
}
int ans = 0;
for (int i = 1; i <= n; ++i)
addmod(ans, dp[c.size() - 1][i]);
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1099 ms |
8312 KB |
Output is correct |
2 |
Correct |
1022 ms |
8332 KB |
Output is correct |
3 |
Correct |
993 ms |
8420 KB |
Output is correct |
4 |
Correct |
1000 ms |
8316 KB |
Output is correct |
5 |
Correct |
1000 ms |
8440 KB |
Output is correct |
6 |
Correct |
906 ms |
8440 KB |
Output is correct |
7 |
Correct |
893 ms |
8312 KB |
Output is correct |
8 |
Correct |
900 ms |
8312 KB |
Output is correct |
9 |
Correct |
955 ms |
8396 KB |
Output is correct |
10 |
Correct |
937 ms |
8404 KB |
Output is correct |
11 |
Correct |
941 ms |
8312 KB |
Output is correct |
12 |
Correct |
956 ms |
8256 KB |
Output is correct |
13 |
Correct |
942 ms |
8312 KB |
Output is correct |
14 |
Correct |
958 ms |
8440 KB |
Output is correct |
15 |
Correct |
965 ms |
8440 KB |
Output is correct |
16 |
Correct |
196 ms |
4984 KB |
Output is correct |
17 |
Correct |
194 ms |
5112 KB |
Output is correct |
18 |
Correct |
194 ms |
4984 KB |
Output is correct |
19 |
Correct |
203 ms |
5112 KB |
Output is correct |
20 |
Correct |
193 ms |
5112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1099 ms |
8312 KB |
Output is correct |
2 |
Correct |
1022 ms |
8332 KB |
Output is correct |
3 |
Correct |
993 ms |
8420 KB |
Output is correct |
4 |
Correct |
1000 ms |
8316 KB |
Output is correct |
5 |
Correct |
1000 ms |
8440 KB |
Output is correct |
6 |
Correct |
906 ms |
8440 KB |
Output is correct |
7 |
Correct |
893 ms |
8312 KB |
Output is correct |
8 |
Correct |
900 ms |
8312 KB |
Output is correct |
9 |
Correct |
955 ms |
8396 KB |
Output is correct |
10 |
Correct |
937 ms |
8404 KB |
Output is correct |
11 |
Correct |
941 ms |
8312 KB |
Output is correct |
12 |
Correct |
956 ms |
8256 KB |
Output is correct |
13 |
Correct |
942 ms |
8312 KB |
Output is correct |
14 |
Correct |
958 ms |
8440 KB |
Output is correct |
15 |
Correct |
965 ms |
8440 KB |
Output is correct |
16 |
Correct |
196 ms |
4984 KB |
Output is correct |
17 |
Correct |
194 ms |
5112 KB |
Output is correct |
18 |
Correct |
194 ms |
4984 KB |
Output is correct |
19 |
Correct |
203 ms |
5112 KB |
Output is correct |
20 |
Correct |
193 ms |
5112 KB |
Output is correct |
21 |
Correct |
933 ms |
8056 KB |
Output is correct |
22 |
Correct |
908 ms |
8048 KB |
Output is correct |
23 |
Correct |
897 ms |
8056 KB |
Output is correct |
24 |
Correct |
906 ms |
7936 KB |
Output is correct |
25 |
Correct |
910 ms |
7972 KB |
Output is correct |
26 |
Correct |
896 ms |
7964 KB |
Output is correct |
27 |
Correct |
970 ms |
8032 KB |
Output is correct |
28 |
Correct |
905 ms |
8056 KB |
Output is correct |
29 |
Correct |
926 ms |
7800 KB |
Output is correct |
30 |
Correct |
884 ms |
8312 KB |
Output is correct |
31 |
Correct |
875 ms |
8440 KB |
Output is correct |
32 |
Correct |
896 ms |
8276 KB |
Output is correct |
33 |
Correct |
891 ms |
8444 KB |
Output is correct |
34 |
Correct |
893 ms |
8476 KB |
Output is correct |
35 |
Correct |
986 ms |
8440 KB |
Output is correct |
36 |
Correct |
993 ms |
8280 KB |
Output is correct |
37 |
Correct |
989 ms |
8568 KB |
Output is correct |
38 |
Correct |
992 ms |
8292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
5112 KB |
Output is correct |
2 |
Correct |
27 ms |
5112 KB |
Output is correct |
3 |
Correct |
28 ms |
5112 KB |
Output is correct |
4 |
Correct |
28 ms |
5240 KB |
Output is correct |
5 |
Correct |
27 ms |
5112 KB |
Output is correct |
6 |
Correct |
30 ms |
5240 KB |
Output is correct |
7 |
Correct |
30 ms |
5112 KB |
Output is correct |
8 |
Correct |
29 ms |
5112 KB |
Output is correct |
9 |
Correct |
30 ms |
5112 KB |
Output is correct |
10 |
Correct |
32 ms |
5112 KB |
Output is correct |
11 |
Correct |
29 ms |
5112 KB |
Output is correct |
12 |
Correct |
27 ms |
5112 KB |
Output is correct |
13 |
Correct |
27 ms |
5112 KB |
Output is correct |
14 |
Correct |
27 ms |
5112 KB |
Output is correct |
15 |
Correct |
29 ms |
5112 KB |
Output is correct |
16 |
Correct |
19 ms |
4728 KB |
Output is correct |
17 |
Correct |
20 ms |
4856 KB |
Output is correct |
18 |
Correct |
19 ms |
4728 KB |
Output is correct |
19 |
Correct |
19 ms |
4728 KB |
Output is correct |
20 |
Correct |
19 ms |
4728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1099 ms |
8312 KB |
Output is correct |
2 |
Correct |
1022 ms |
8332 KB |
Output is correct |
3 |
Correct |
993 ms |
8420 KB |
Output is correct |
4 |
Correct |
1000 ms |
8316 KB |
Output is correct |
5 |
Correct |
1000 ms |
8440 KB |
Output is correct |
6 |
Correct |
906 ms |
8440 KB |
Output is correct |
7 |
Correct |
893 ms |
8312 KB |
Output is correct |
8 |
Correct |
900 ms |
8312 KB |
Output is correct |
9 |
Correct |
955 ms |
8396 KB |
Output is correct |
10 |
Correct |
937 ms |
8404 KB |
Output is correct |
11 |
Correct |
941 ms |
8312 KB |
Output is correct |
12 |
Correct |
956 ms |
8256 KB |
Output is correct |
13 |
Correct |
942 ms |
8312 KB |
Output is correct |
14 |
Correct |
958 ms |
8440 KB |
Output is correct |
15 |
Correct |
965 ms |
8440 KB |
Output is correct |
16 |
Correct |
196 ms |
4984 KB |
Output is correct |
17 |
Correct |
194 ms |
5112 KB |
Output is correct |
18 |
Correct |
194 ms |
4984 KB |
Output is correct |
19 |
Correct |
203 ms |
5112 KB |
Output is correct |
20 |
Correct |
193 ms |
5112 KB |
Output is correct |
21 |
Correct |
933 ms |
8056 KB |
Output is correct |
22 |
Correct |
908 ms |
8048 KB |
Output is correct |
23 |
Correct |
897 ms |
8056 KB |
Output is correct |
24 |
Correct |
906 ms |
7936 KB |
Output is correct |
25 |
Correct |
910 ms |
7972 KB |
Output is correct |
26 |
Correct |
896 ms |
7964 KB |
Output is correct |
27 |
Correct |
970 ms |
8032 KB |
Output is correct |
28 |
Correct |
905 ms |
8056 KB |
Output is correct |
29 |
Correct |
926 ms |
7800 KB |
Output is correct |
30 |
Correct |
884 ms |
8312 KB |
Output is correct |
31 |
Correct |
875 ms |
8440 KB |
Output is correct |
32 |
Correct |
896 ms |
8276 KB |
Output is correct |
33 |
Correct |
891 ms |
8444 KB |
Output is correct |
34 |
Correct |
893 ms |
8476 KB |
Output is correct |
35 |
Correct |
986 ms |
8440 KB |
Output is correct |
36 |
Correct |
993 ms |
8280 KB |
Output is correct |
37 |
Correct |
989 ms |
8568 KB |
Output is correct |
38 |
Correct |
992 ms |
8292 KB |
Output is correct |
39 |
Correct |
28 ms |
5112 KB |
Output is correct |
40 |
Correct |
27 ms |
5112 KB |
Output is correct |
41 |
Correct |
28 ms |
5112 KB |
Output is correct |
42 |
Correct |
28 ms |
5240 KB |
Output is correct |
43 |
Correct |
27 ms |
5112 KB |
Output is correct |
44 |
Correct |
30 ms |
5240 KB |
Output is correct |
45 |
Correct |
30 ms |
5112 KB |
Output is correct |
46 |
Correct |
29 ms |
5112 KB |
Output is correct |
47 |
Correct |
30 ms |
5112 KB |
Output is correct |
48 |
Correct |
32 ms |
5112 KB |
Output is correct |
49 |
Correct |
29 ms |
5112 KB |
Output is correct |
50 |
Correct |
27 ms |
5112 KB |
Output is correct |
51 |
Correct |
27 ms |
5112 KB |
Output is correct |
52 |
Correct |
27 ms |
5112 KB |
Output is correct |
53 |
Correct |
29 ms |
5112 KB |
Output is correct |
54 |
Correct |
19 ms |
4728 KB |
Output is correct |
55 |
Correct |
20 ms |
4856 KB |
Output is correct |
56 |
Correct |
19 ms |
4728 KB |
Output is correct |
57 |
Correct |
19 ms |
4728 KB |
Output is correct |
58 |
Correct |
19 ms |
4728 KB |
Output is correct |
59 |
Execution timed out |
2087 ms |
8416 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |