//#define _GLIBCXX_DEBUG
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less < T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using normal_queue = priority_queue <T, vector<T>, greater<>>;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define trace(x) cout << #x << ": " << (x) << endl;
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define uniq(x) x.resize(unique(all(x)) - begin(x))
#define ld long double
#define sz(s) ((int) size(s))
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define int128 __int128
#define pb push_back
#define eb emplace_back
template<typename T>
bool ckmin(T &x, T y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template<typename T>
bool ckmax(T &x, T y) {
if (x < y) {
x = y;
return true;
}
return false;
}
int bit(int x, int b) {
return (x >> b) & 1;
}
int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }
//soryan za musor sverhu
const ll infL = 3e18;
const int infI = 1'000'000'000 + 7;
const int N = 1001;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
ll fastp(ll a, ll p) {
ll ans = 1;
a %= mod;
while (p) {
if (p & 1)
ans = ans * a % mod;
a = a * a % mod;
p >>= 1;
}
return ans;
}
ll fac[N];
ll invfac[N];
ll invnum[N];
void init() {
int n = N - 1;
fac[0] = invnum[0] = invfac[0] = 1;
for (int i = 1; i <= n; ++i) {
fac[i] = fac[i - 1] * i % mod;
}
invfac[n] = fastp(fac[n], mod - 2);
invnum[n] = invfac[n] * fac[n - 1] % mod;
for (int i = n - 1; i > 0; --i) {
invfac[i] = invfac[i + 1] * (i + 1) % mod;
invnum[i] = invfac[i] * fac[i - 1] % mod;
}
}
ll inv(ll a) {
if (a < N) return invnum[a];
return fastp(a, mod - 2);
}
ll cnk(int n, int k) {
if (k < 0 || k > n) return 0;
return fac[n] * invfac[n - k] % mod * invfac[k] % mod;
}
ll dp[N][N];
int A[N], B[N], cord[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
init();
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> A[i] >> B[i];
++B[i];
cord[(i - 1) * 2] = A[i];
cord[(i - 1) * 2 + 1] = B[i];
}
sort(cord, cord + n * 2);
int m = unique(cord, cord + 2 * n) - cord;
for (int i = 1; i <= n; ++i) {
A[i] = lower_bound(cord, cord + m, A[i]) - cord + 1;
B[i] = lower_bound(cord, cord + m, B[i]) - cord + 1;
}
for (int i = 0; i < m; ++i) dp[0][i] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = A[i]; j < B[i]; ++j) {
ll len = cord[j] - cord[j - 1];
ll x = len;
int cnt = 1;
//this number is C(len + cnt - 1, cnt - 1)
//so when we increase cnt, x = x * (len + cnt - 1) / cnt
//because the last one is 100% not zero
for (int k = i - 1; k >= 0; --k) {
dp[i][j] = (dp[i][j] + x * dp[k][j - 1]) % mod;
if (A[k] <= j && j < B[k]) {
++cnt;
x = x * (len + cnt - 1) % mod * inv(cnt) % mod;
}
}
}
for (int j = 1; j < N; ++j) {
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
}
}
ll ans = 0;
for (int i = 1; i <= n; ++i) {
ans = (ans + dp[i][N - 1]) % mod;
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4180 KB |
Output is correct |
2 |
Correct |
7 ms |
4180 KB |
Output is correct |
3 |
Correct |
6 ms |
4180 KB |
Output is correct |
4 |
Correct |
7 ms |
4252 KB |
Output is correct |
5 |
Correct |
7 ms |
4204 KB |
Output is correct |
6 |
Correct |
7 ms |
4308 KB |
Output is correct |
7 |
Correct |
6 ms |
4180 KB |
Output is correct |
8 |
Correct |
7 ms |
4200 KB |
Output is correct |
9 |
Correct |
7 ms |
4204 KB |
Output is correct |
10 |
Correct |
7 ms |
4308 KB |
Output is correct |
11 |
Correct |
6 ms |
4204 KB |
Output is correct |
12 |
Correct |
6 ms |
4180 KB |
Output is correct |
13 |
Correct |
6 ms |
4308 KB |
Output is correct |
14 |
Correct |
6 ms |
4200 KB |
Output is correct |
15 |
Correct |
7 ms |
4264 KB |
Output is correct |
16 |
Correct |
6 ms |
4240 KB |
Output is correct |
17 |
Correct |
6 ms |
4180 KB |
Output is correct |
18 |
Correct |
7 ms |
4232 KB |
Output is correct |
19 |
Correct |
7 ms |
4180 KB |
Output is correct |
20 |
Correct |
6 ms |
4180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4180 KB |
Output is correct |
2 |
Correct |
7 ms |
4180 KB |
Output is correct |
3 |
Correct |
6 ms |
4180 KB |
Output is correct |
4 |
Correct |
7 ms |
4252 KB |
Output is correct |
5 |
Correct |
7 ms |
4204 KB |
Output is correct |
6 |
Correct |
7 ms |
4308 KB |
Output is correct |
7 |
Correct |
6 ms |
4180 KB |
Output is correct |
8 |
Correct |
7 ms |
4200 KB |
Output is correct |
9 |
Correct |
7 ms |
4204 KB |
Output is correct |
10 |
Correct |
7 ms |
4308 KB |
Output is correct |
11 |
Correct |
6 ms |
4204 KB |
Output is correct |
12 |
Correct |
6 ms |
4180 KB |
Output is correct |
13 |
Correct |
6 ms |
4308 KB |
Output is correct |
14 |
Correct |
6 ms |
4200 KB |
Output is correct |
15 |
Correct |
7 ms |
4264 KB |
Output is correct |
16 |
Correct |
6 ms |
4240 KB |
Output is correct |
17 |
Correct |
6 ms |
4180 KB |
Output is correct |
18 |
Correct |
7 ms |
4232 KB |
Output is correct |
19 |
Correct |
7 ms |
4180 KB |
Output is correct |
20 |
Correct |
6 ms |
4180 KB |
Output is correct |
21 |
Correct |
228 ms |
4184 KB |
Output is correct |
22 |
Correct |
224 ms |
4164 KB |
Output is correct |
23 |
Correct |
211 ms |
4172 KB |
Output is correct |
24 |
Correct |
218 ms |
4160 KB |
Output is correct |
25 |
Correct |
230 ms |
4220 KB |
Output is correct |
26 |
Correct |
451 ms |
4252 KB |
Output is correct |
27 |
Correct |
467 ms |
4300 KB |
Output is correct |
28 |
Correct |
462 ms |
4204 KB |
Output is correct |
29 |
Correct |
441 ms |
4172 KB |
Output is correct |
30 |
Correct |
7 ms |
4180 KB |
Output is correct |
31 |
Correct |
7 ms |
4180 KB |
Output is correct |
32 |
Correct |
7 ms |
4180 KB |
Output is correct |
33 |
Correct |
7 ms |
4220 KB |
Output is correct |
34 |
Correct |
7 ms |
4204 KB |
Output is correct |
35 |
Correct |
7 ms |
4180 KB |
Output is correct |
36 |
Correct |
9 ms |
4204 KB |
Output is correct |
37 |
Correct |
9 ms |
4180 KB |
Output is correct |
38 |
Correct |
8 ms |
4208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1108 KB |
Output is correct |
2 |
Correct |
3 ms |
1108 KB |
Output is correct |
3 |
Correct |
3 ms |
1108 KB |
Output is correct |
4 |
Correct |
3 ms |
1108 KB |
Output is correct |
5 |
Correct |
3 ms |
1108 KB |
Output is correct |
6 |
Correct |
5 ms |
1108 KB |
Output is correct |
7 |
Correct |
5 ms |
1124 KB |
Output is correct |
8 |
Correct |
5 ms |
1040 KB |
Output is correct |
9 |
Correct |
5 ms |
1056 KB |
Output is correct |
10 |
Correct |
6 ms |
1096 KB |
Output is correct |
11 |
Correct |
3 ms |
1108 KB |
Output is correct |
12 |
Correct |
3 ms |
1088 KB |
Output is correct |
13 |
Correct |
4 ms |
1124 KB |
Output is correct |
14 |
Correct |
3 ms |
1108 KB |
Output is correct |
15 |
Correct |
4 ms |
1108 KB |
Output is correct |
16 |
Correct |
3 ms |
1128 KB |
Output is correct |
17 |
Correct |
4 ms |
1120 KB |
Output is correct |
18 |
Correct |
3 ms |
1108 KB |
Output is correct |
19 |
Correct |
3 ms |
1108 KB |
Output is correct |
20 |
Correct |
3 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4180 KB |
Output is correct |
2 |
Correct |
7 ms |
4180 KB |
Output is correct |
3 |
Correct |
6 ms |
4180 KB |
Output is correct |
4 |
Correct |
7 ms |
4252 KB |
Output is correct |
5 |
Correct |
7 ms |
4204 KB |
Output is correct |
6 |
Correct |
7 ms |
4308 KB |
Output is correct |
7 |
Correct |
6 ms |
4180 KB |
Output is correct |
8 |
Correct |
7 ms |
4200 KB |
Output is correct |
9 |
Correct |
7 ms |
4204 KB |
Output is correct |
10 |
Correct |
7 ms |
4308 KB |
Output is correct |
11 |
Correct |
6 ms |
4204 KB |
Output is correct |
12 |
Correct |
6 ms |
4180 KB |
Output is correct |
13 |
Correct |
6 ms |
4308 KB |
Output is correct |
14 |
Correct |
6 ms |
4200 KB |
Output is correct |
15 |
Correct |
7 ms |
4264 KB |
Output is correct |
16 |
Correct |
6 ms |
4240 KB |
Output is correct |
17 |
Correct |
6 ms |
4180 KB |
Output is correct |
18 |
Correct |
7 ms |
4232 KB |
Output is correct |
19 |
Correct |
7 ms |
4180 KB |
Output is correct |
20 |
Correct |
6 ms |
4180 KB |
Output is correct |
21 |
Correct |
228 ms |
4184 KB |
Output is correct |
22 |
Correct |
224 ms |
4164 KB |
Output is correct |
23 |
Correct |
211 ms |
4172 KB |
Output is correct |
24 |
Correct |
218 ms |
4160 KB |
Output is correct |
25 |
Correct |
230 ms |
4220 KB |
Output is correct |
26 |
Correct |
451 ms |
4252 KB |
Output is correct |
27 |
Correct |
467 ms |
4300 KB |
Output is correct |
28 |
Correct |
462 ms |
4204 KB |
Output is correct |
29 |
Correct |
441 ms |
4172 KB |
Output is correct |
30 |
Correct |
7 ms |
4180 KB |
Output is correct |
31 |
Correct |
7 ms |
4180 KB |
Output is correct |
32 |
Correct |
7 ms |
4180 KB |
Output is correct |
33 |
Correct |
7 ms |
4220 KB |
Output is correct |
34 |
Correct |
7 ms |
4204 KB |
Output is correct |
35 |
Correct |
7 ms |
4180 KB |
Output is correct |
36 |
Correct |
9 ms |
4204 KB |
Output is correct |
37 |
Correct |
9 ms |
4180 KB |
Output is correct |
38 |
Correct |
8 ms |
4208 KB |
Output is correct |
39 |
Correct |
3 ms |
1108 KB |
Output is correct |
40 |
Correct |
3 ms |
1108 KB |
Output is correct |
41 |
Correct |
3 ms |
1108 KB |
Output is correct |
42 |
Correct |
3 ms |
1108 KB |
Output is correct |
43 |
Correct |
3 ms |
1108 KB |
Output is correct |
44 |
Correct |
5 ms |
1108 KB |
Output is correct |
45 |
Correct |
5 ms |
1124 KB |
Output is correct |
46 |
Correct |
5 ms |
1040 KB |
Output is correct |
47 |
Correct |
5 ms |
1056 KB |
Output is correct |
48 |
Correct |
6 ms |
1096 KB |
Output is correct |
49 |
Correct |
3 ms |
1108 KB |
Output is correct |
50 |
Correct |
3 ms |
1088 KB |
Output is correct |
51 |
Correct |
4 ms |
1124 KB |
Output is correct |
52 |
Correct |
3 ms |
1108 KB |
Output is correct |
53 |
Correct |
4 ms |
1108 KB |
Output is correct |
54 |
Correct |
3 ms |
1128 KB |
Output is correct |
55 |
Correct |
4 ms |
1120 KB |
Output is correct |
56 |
Correct |
3 ms |
1108 KB |
Output is correct |
57 |
Correct |
3 ms |
1108 KB |
Output is correct |
58 |
Correct |
3 ms |
1108 KB |
Output is correct |
59 |
Correct |
241 ms |
4240 KB |
Output is correct |
60 |
Correct |
241 ms |
4268 KB |
Output is correct |
61 |
Correct |
219 ms |
4252 KB |
Output is correct |
62 |
Correct |
240 ms |
4216 KB |
Output is correct |
63 |
Correct |
256 ms |
4236 KB |
Output is correct |
64 |
Correct |
504 ms |
4240 KB |
Output is correct |
65 |
Correct |
526 ms |
4204 KB |
Output is correct |
66 |
Correct |
525 ms |
4308 KB |
Output is correct |
67 |
Correct |
515 ms |
4200 KB |
Output is correct |
68 |
Correct |
520 ms |
4200 KB |
Output is correct |
69 |
Correct |
228 ms |
4236 KB |
Output is correct |
70 |
Correct |
207 ms |
4384 KB |
Output is correct |
71 |
Correct |
215 ms |
4156 KB |
Output is correct |
72 |
Correct |
211 ms |
4188 KB |
Output is correct |
73 |
Correct |
215 ms |
4188 KB |
Output is correct |
74 |
Correct |
55 ms |
4236 KB |
Output is correct |
75 |
Correct |
52 ms |
4168 KB |
Output is correct |
76 |
Correct |
55 ms |
4180 KB |
Output is correct |
77 |
Correct |
56 ms |
4176 KB |
Output is correct |
78 |
Correct |
55 ms |
4232 KB |
Output is correct |