#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
const int MX_N = 505;
const int MOD = 1e9+7;
int N, A[MX_N], B[MX_N];
vector<int> val;
int inv[MX_N];
int f[MX_N][2*MX_N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
FOR(i,1,N){
cin >> A[i] >> B[i];
B[i] += 1;
val.push_back(A[i]);
val.push_back(B[i]);
}
sort(ALL(val));
val.resize(unique(ALL(val))-val.begin());
FOR(i,1,N){
A[i] = lower_bound(ALL(val),A[i])-val.begin();
B[i] = lower_bound(ALL(val),B[i])-val.begin();
}
inv[1] = 1; FOR(i,2,N) inv[i] = (long long) (MOD-MOD/i) * inv[MOD%i] % MOD;
FOR(p,0,SZ(val)-1) f[N+1][p] = 1;
FOR(i,1,N) f[i][SZ(val)] = 0;
RFOR(p,SZ(val)-2,0){
int lp = val[p+1]-val[p];
RFOR(i,N,1){
f[i][p] = 0;
if (p < SZ(val)-1) f[i][p] = (f[i][p] + f[i][p+1]) % MOD;
if (A[i] <= p && p < B[i]) {
int m = 0;
int g = lp;
FOR(j,i+1,N+1){
f[i][p] = (f[i][p] + (long long) g * f[j][p+1] % MOD) % MOD;
if (A[j] <= p && p < B[j]) {
++m;
g = (long long) g * (m + lp) % MOD * inv[m+1] % MOD;
}
}
}
//TRACE(i _ p _ f[i][p]);
}
}
int ans = 0;
FOR(i,1,N) ans = (ans + f[i][0]) % MOD;
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2304 KB |
Output is correct |
2 |
Correct |
8 ms |
2304 KB |
Output is correct |
3 |
Correct |
8 ms |
2304 KB |
Output is correct |
4 |
Correct |
8 ms |
2304 KB |
Output is correct |
5 |
Correct |
8 ms |
2304 KB |
Output is correct |
6 |
Correct |
8 ms |
2304 KB |
Output is correct |
7 |
Correct |
8 ms |
2304 KB |
Output is correct |
8 |
Correct |
8 ms |
2304 KB |
Output is correct |
9 |
Correct |
8 ms |
2304 KB |
Output is correct |
10 |
Correct |
8 ms |
2304 KB |
Output is correct |
11 |
Correct |
8 ms |
2304 KB |
Output is correct |
12 |
Correct |
8 ms |
2304 KB |
Output is correct |
13 |
Correct |
8 ms |
2304 KB |
Output is correct |
14 |
Correct |
8 ms |
2304 KB |
Output is correct |
15 |
Correct |
8 ms |
2304 KB |
Output is correct |
16 |
Correct |
7 ms |
2304 KB |
Output is correct |
17 |
Correct |
7 ms |
2304 KB |
Output is correct |
18 |
Correct |
7 ms |
2304 KB |
Output is correct |
19 |
Correct |
7 ms |
2304 KB |
Output is correct |
20 |
Correct |
7 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2304 KB |
Output is correct |
2 |
Correct |
8 ms |
2304 KB |
Output is correct |
3 |
Correct |
8 ms |
2304 KB |
Output is correct |
4 |
Correct |
8 ms |
2304 KB |
Output is correct |
5 |
Correct |
8 ms |
2304 KB |
Output is correct |
6 |
Correct |
8 ms |
2304 KB |
Output is correct |
7 |
Correct |
8 ms |
2304 KB |
Output is correct |
8 |
Correct |
8 ms |
2304 KB |
Output is correct |
9 |
Correct |
8 ms |
2304 KB |
Output is correct |
10 |
Correct |
8 ms |
2304 KB |
Output is correct |
11 |
Correct |
8 ms |
2304 KB |
Output is correct |
12 |
Correct |
8 ms |
2304 KB |
Output is correct |
13 |
Correct |
8 ms |
2304 KB |
Output is correct |
14 |
Correct |
8 ms |
2304 KB |
Output is correct |
15 |
Correct |
8 ms |
2304 KB |
Output is correct |
16 |
Correct |
7 ms |
2304 KB |
Output is correct |
17 |
Correct |
7 ms |
2304 KB |
Output is correct |
18 |
Correct |
7 ms |
2304 KB |
Output is correct |
19 |
Correct |
7 ms |
2304 KB |
Output is correct |
20 |
Correct |
7 ms |
2304 KB |
Output is correct |
21 |
Correct |
322 ms |
2424 KB |
Output is correct |
22 |
Correct |
316 ms |
2424 KB |
Output is correct |
23 |
Correct |
296 ms |
2304 KB |
Output is correct |
24 |
Correct |
305 ms |
2424 KB |
Output is correct |
25 |
Correct |
333 ms |
2304 KB |
Output is correct |
26 |
Correct |
563 ms |
2424 KB |
Output is correct |
27 |
Correct |
579 ms |
2424 KB |
Output is correct |
28 |
Correct |
568 ms |
2424 KB |
Output is correct |
29 |
Correct |
560 ms |
2424 KB |
Output is correct |
30 |
Correct |
9 ms |
2304 KB |
Output is correct |
31 |
Correct |
9 ms |
2304 KB |
Output is correct |
32 |
Correct |
10 ms |
2304 KB |
Output is correct |
33 |
Correct |
10 ms |
2304 KB |
Output is correct |
34 |
Correct |
9 ms |
2304 KB |
Output is correct |
35 |
Correct |
9 ms |
2304 KB |
Output is correct |
36 |
Correct |
10 ms |
2480 KB |
Output is correct |
37 |
Correct |
10 ms |
2304 KB |
Output is correct |
38 |
Correct |
10 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
768 KB |
Output is correct |
2 |
Correct |
9 ms |
768 KB |
Output is correct |
3 |
Correct |
8 ms |
768 KB |
Output is correct |
4 |
Correct |
8 ms |
768 KB |
Output is correct |
5 |
Correct |
8 ms |
820 KB |
Output is correct |
6 |
Correct |
10 ms |
768 KB |
Output is correct |
7 |
Correct |
10 ms |
768 KB |
Output is correct |
8 |
Correct |
10 ms |
768 KB |
Output is correct |
9 |
Correct |
10 ms |
768 KB |
Output is correct |
10 |
Correct |
10 ms |
768 KB |
Output is correct |
11 |
Correct |
8 ms |
768 KB |
Output is correct |
12 |
Correct |
7 ms |
768 KB |
Output is correct |
13 |
Correct |
8 ms |
768 KB |
Output is correct |
14 |
Correct |
8 ms |
768 KB |
Output is correct |
15 |
Correct |
8 ms |
768 KB |
Output is correct |
16 |
Correct |
7 ms |
768 KB |
Output is correct |
17 |
Correct |
6 ms |
768 KB |
Output is correct |
18 |
Correct |
7 ms |
768 KB |
Output is correct |
19 |
Correct |
6 ms |
768 KB |
Output is correct |
20 |
Correct |
6 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2304 KB |
Output is correct |
2 |
Correct |
8 ms |
2304 KB |
Output is correct |
3 |
Correct |
8 ms |
2304 KB |
Output is correct |
4 |
Correct |
8 ms |
2304 KB |
Output is correct |
5 |
Correct |
8 ms |
2304 KB |
Output is correct |
6 |
Correct |
8 ms |
2304 KB |
Output is correct |
7 |
Correct |
8 ms |
2304 KB |
Output is correct |
8 |
Correct |
8 ms |
2304 KB |
Output is correct |
9 |
Correct |
8 ms |
2304 KB |
Output is correct |
10 |
Correct |
8 ms |
2304 KB |
Output is correct |
11 |
Correct |
8 ms |
2304 KB |
Output is correct |
12 |
Correct |
8 ms |
2304 KB |
Output is correct |
13 |
Correct |
8 ms |
2304 KB |
Output is correct |
14 |
Correct |
8 ms |
2304 KB |
Output is correct |
15 |
Correct |
8 ms |
2304 KB |
Output is correct |
16 |
Correct |
7 ms |
2304 KB |
Output is correct |
17 |
Correct |
7 ms |
2304 KB |
Output is correct |
18 |
Correct |
7 ms |
2304 KB |
Output is correct |
19 |
Correct |
7 ms |
2304 KB |
Output is correct |
20 |
Correct |
7 ms |
2304 KB |
Output is correct |
21 |
Correct |
322 ms |
2424 KB |
Output is correct |
22 |
Correct |
316 ms |
2424 KB |
Output is correct |
23 |
Correct |
296 ms |
2304 KB |
Output is correct |
24 |
Correct |
305 ms |
2424 KB |
Output is correct |
25 |
Correct |
333 ms |
2304 KB |
Output is correct |
26 |
Correct |
563 ms |
2424 KB |
Output is correct |
27 |
Correct |
579 ms |
2424 KB |
Output is correct |
28 |
Correct |
568 ms |
2424 KB |
Output is correct |
29 |
Correct |
560 ms |
2424 KB |
Output is correct |
30 |
Correct |
9 ms |
2304 KB |
Output is correct |
31 |
Correct |
9 ms |
2304 KB |
Output is correct |
32 |
Correct |
10 ms |
2304 KB |
Output is correct |
33 |
Correct |
10 ms |
2304 KB |
Output is correct |
34 |
Correct |
9 ms |
2304 KB |
Output is correct |
35 |
Correct |
9 ms |
2304 KB |
Output is correct |
36 |
Correct |
10 ms |
2480 KB |
Output is correct |
37 |
Correct |
10 ms |
2304 KB |
Output is correct |
38 |
Correct |
10 ms |
2304 KB |
Output is correct |
39 |
Correct |
8 ms |
768 KB |
Output is correct |
40 |
Correct |
9 ms |
768 KB |
Output is correct |
41 |
Correct |
8 ms |
768 KB |
Output is correct |
42 |
Correct |
8 ms |
768 KB |
Output is correct |
43 |
Correct |
8 ms |
820 KB |
Output is correct |
44 |
Correct |
10 ms |
768 KB |
Output is correct |
45 |
Correct |
10 ms |
768 KB |
Output is correct |
46 |
Correct |
10 ms |
768 KB |
Output is correct |
47 |
Correct |
10 ms |
768 KB |
Output is correct |
48 |
Correct |
10 ms |
768 KB |
Output is correct |
49 |
Correct |
8 ms |
768 KB |
Output is correct |
50 |
Correct |
7 ms |
768 KB |
Output is correct |
51 |
Correct |
8 ms |
768 KB |
Output is correct |
52 |
Correct |
8 ms |
768 KB |
Output is correct |
53 |
Correct |
8 ms |
768 KB |
Output is correct |
54 |
Correct |
7 ms |
768 KB |
Output is correct |
55 |
Correct |
6 ms |
768 KB |
Output is correct |
56 |
Correct |
7 ms |
768 KB |
Output is correct |
57 |
Correct |
6 ms |
768 KB |
Output is correct |
58 |
Correct |
6 ms |
768 KB |
Output is correct |
59 |
Correct |
359 ms |
2304 KB |
Output is correct |
60 |
Correct |
331 ms |
2304 KB |
Output is correct |
61 |
Correct |
320 ms |
2304 KB |
Output is correct |
62 |
Correct |
363 ms |
2428 KB |
Output is correct |
63 |
Correct |
349 ms |
2392 KB |
Output is correct |
64 |
Correct |
646 ms |
2424 KB |
Output is correct |
65 |
Correct |
645 ms |
2400 KB |
Output is correct |
66 |
Correct |
635 ms |
2424 KB |
Output is correct |
67 |
Correct |
655 ms |
2424 KB |
Output is correct |
68 |
Correct |
650 ms |
2304 KB |
Output is correct |
69 |
Correct |
360 ms |
2424 KB |
Output is correct |
70 |
Correct |
390 ms |
2304 KB |
Output is correct |
71 |
Correct |
380 ms |
2424 KB |
Output is correct |
72 |
Correct |
397 ms |
2424 KB |
Output is correct |
73 |
Correct |
376 ms |
2424 KB |
Output is correct |
74 |
Correct |
73 ms |
2304 KB |
Output is correct |
75 |
Correct |
78 ms |
2432 KB |
Output is correct |
76 |
Correct |
82 ms |
2304 KB |
Output is correct |
77 |
Correct |
73 ms |
2304 KB |
Output is correct |
78 |
Correct |
74 ms |
2432 KB |
Output is correct |