#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 20, MOD = (int)1e9+7;
ll binpow(ll a,ll b) {
ll ans = 1,k = a;
while(b) {
if(b % 2)ans *= k;
ans %= MOD;
k *= k;
k %= MOD;
b /= 2ll;
}
return ans;
}
ll bp[N];
ll ceis(ll n,ll k){
if(k > n) return 0;
ll d = 1;
for(ll i = n - k + 1;i <= n;i++){
d = i % MOD * d % MOD;
}
for(ll i = 2;i <= k;i++){
d = d * bp[i]%MOD;
}
return d;
}
int n;
array<int,2> a[N];
vector<int> b;
vector<array<int,2>> o;
ll dp[N][N],pref[N][N],c[N][N],prec[N/2][N/2];
int m;
void test(){
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a[i][0] >> a[i][1];
b.push_back(a[i][0]);
b.push_back(a[i][1] + 1);
bp[i] = binpow(i,MOD-2);
}
sort(b.begin(),b.end());
b.resize(unique(b.begin(),b.end()) - b.begin());
for(int i = 1;i < (int)b.size();i++){
o.push_back({b[i-1],b[i]-1});
}
int m = (int)o.size();
for(int i = 0;i <= m;i++){
pref[0][i] = 1;
}
for(int i = 0;i <= n;i++){
for(int j = 0;j <= i;j++){
prec[i][j] = ceis(i,j);
}
}
for(int i = 1;i <= m;i++){
int s = (o[i - 1][1] - o[i - 1][0]+1);
c[i][1] = s;
vector<int> C(n+1,0);
for(int j = 0;j <= n;++j){
C[j] = ceis(s,j);
}
for(int j = 2;j <= n;j++){
for(int k = 0;k <= j-2;k++){
c[i][j] = (c[i][j] + prec[j-2][k]*1ll*C[j-k]%MOD);
if(c[i][j] >= MOD) c[i][j] -= MOD;
}
}
}
for(int i = 1;i <= n;i++){
pref[i][0] = 1;
for(int j = 1;j <= m;j++){
dp[i][j] = dp[i - 1][j];
if(a[i][0] <= o[j - 1][0] && a[i][1] >= o[j-1][1]){
for(int k = i,col = 0;k >= 1;k--){
if(a[k][0] <= o[j-1][0] && a[k][1] >= o[j-1][1]){
++col;
dp[i][j] += pref[k-1][j-1]*1ll*c[j][col]%MOD;
if(dp[j][j] >= MOD) dp[i][j] -= MOD;
}
}
}
}
for(int j = 1;j <= m;j++){
pref[i][j] = (pref[i][j - 1] + dp[i][j])%MOD;
}
}
cout << (pref[n][m]-1+MOD)%MOD << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);cin.tie(0);
int t = 1;
// cin >> t;
while(t--){
test();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
865 ms |
18772 KB |
Output is correct |
2 |
Correct |
938 ms |
19084 KB |
Output is correct |
3 |
Correct |
928 ms |
18836 KB |
Output is correct |
4 |
Correct |
919 ms |
18836 KB |
Output is correct |
5 |
Correct |
943 ms |
19028 KB |
Output is correct |
6 |
Correct |
940 ms |
18832 KB |
Output is correct |
7 |
Correct |
873 ms |
18772 KB |
Output is correct |
8 |
Correct |
888 ms |
18836 KB |
Output is correct |
9 |
Correct |
926 ms |
18836 KB |
Output is correct |
10 |
Correct |
888 ms |
18836 KB |
Output is correct |
11 |
Correct |
910 ms |
18836 KB |
Output is correct |
12 |
Correct |
898 ms |
19092 KB |
Output is correct |
13 |
Correct |
878 ms |
18832 KB |
Output is correct |
14 |
Correct |
909 ms |
18832 KB |
Output is correct |
15 |
Correct |
846 ms |
18832 KB |
Output is correct |
16 |
Correct |
293 ms |
14480 KB |
Output is correct |
17 |
Correct |
301 ms |
14420 KB |
Output is correct |
18 |
Correct |
318 ms |
14416 KB |
Output is correct |
19 |
Correct |
322 ms |
14480 KB |
Output is correct |
20 |
Correct |
315 ms |
14468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
865 ms |
18772 KB |
Output is correct |
2 |
Correct |
938 ms |
19084 KB |
Output is correct |
3 |
Correct |
928 ms |
18836 KB |
Output is correct |
4 |
Correct |
919 ms |
18836 KB |
Output is correct |
5 |
Correct |
943 ms |
19028 KB |
Output is correct |
6 |
Correct |
940 ms |
18832 KB |
Output is correct |
7 |
Correct |
873 ms |
18772 KB |
Output is correct |
8 |
Correct |
888 ms |
18836 KB |
Output is correct |
9 |
Correct |
926 ms |
18836 KB |
Output is correct |
10 |
Correct |
888 ms |
18836 KB |
Output is correct |
11 |
Correct |
910 ms |
18836 KB |
Output is correct |
12 |
Correct |
898 ms |
19092 KB |
Output is correct |
13 |
Correct |
878 ms |
18832 KB |
Output is correct |
14 |
Correct |
909 ms |
18832 KB |
Output is correct |
15 |
Correct |
846 ms |
18832 KB |
Output is correct |
16 |
Correct |
293 ms |
14480 KB |
Output is correct |
17 |
Correct |
301 ms |
14420 KB |
Output is correct |
18 |
Correct |
318 ms |
14416 KB |
Output is correct |
19 |
Correct |
322 ms |
14480 KB |
Output is correct |
20 |
Correct |
315 ms |
14468 KB |
Output is correct |
21 |
Correct |
476 ms |
18768 KB |
Output is correct |
22 |
Correct |
492 ms |
18840 KB |
Output is correct |
23 |
Correct |
471 ms |
18772 KB |
Output is correct |
24 |
Correct |
469 ms |
19028 KB |
Output is correct |
25 |
Correct |
434 ms |
18840 KB |
Output is correct |
26 |
Correct |
488 ms |
18768 KB |
Output is correct |
27 |
Correct |
552 ms |
18836 KB |
Output is correct |
28 |
Correct |
469 ms |
19024 KB |
Output is correct |
29 |
Correct |
506 ms |
18768 KB |
Output is correct |
30 |
Correct |
803 ms |
18828 KB |
Output is correct |
31 |
Correct |
830 ms |
18768 KB |
Output is correct |
32 |
Correct |
874 ms |
18836 KB |
Output is correct |
33 |
Correct |
820 ms |
18840 KB |
Output is correct |
34 |
Correct |
829 ms |
18848 KB |
Output is correct |
35 |
Correct |
829 ms |
18840 KB |
Output is correct |
36 |
Correct |
846 ms |
18844 KB |
Output is correct |
37 |
Correct |
887 ms |
18836 KB |
Output is correct |
38 |
Correct |
884 ms |
18836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
9308 KB |
Output is correct |
2 |
Correct |
14 ms |
9308 KB |
Output is correct |
3 |
Correct |
14 ms |
9308 KB |
Output is correct |
4 |
Correct |
15 ms |
9360 KB |
Output is correct |
5 |
Correct |
14 ms |
9308 KB |
Output is correct |
6 |
Correct |
15 ms |
9308 KB |
Output is correct |
7 |
Correct |
15 ms |
9308 KB |
Output is correct |
8 |
Correct |
14 ms |
9308 KB |
Output is correct |
9 |
Correct |
14 ms |
9360 KB |
Output is correct |
10 |
Correct |
14 ms |
9356 KB |
Output is correct |
11 |
Correct |
14 ms |
9308 KB |
Output is correct |
12 |
Correct |
13 ms |
9308 KB |
Output is correct |
13 |
Correct |
13 ms |
9364 KB |
Output is correct |
14 |
Correct |
15 ms |
9308 KB |
Output is correct |
15 |
Correct |
14 ms |
9308 KB |
Output is correct |
16 |
Correct |
8 ms |
9352 KB |
Output is correct |
17 |
Correct |
8 ms |
9308 KB |
Output is correct |
18 |
Correct |
8 ms |
9308 KB |
Output is correct |
19 |
Correct |
8 ms |
9304 KB |
Output is correct |
20 |
Correct |
9 ms |
9612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
865 ms |
18772 KB |
Output is correct |
2 |
Correct |
938 ms |
19084 KB |
Output is correct |
3 |
Correct |
928 ms |
18836 KB |
Output is correct |
4 |
Correct |
919 ms |
18836 KB |
Output is correct |
5 |
Correct |
943 ms |
19028 KB |
Output is correct |
6 |
Correct |
940 ms |
18832 KB |
Output is correct |
7 |
Correct |
873 ms |
18772 KB |
Output is correct |
8 |
Correct |
888 ms |
18836 KB |
Output is correct |
9 |
Correct |
926 ms |
18836 KB |
Output is correct |
10 |
Correct |
888 ms |
18836 KB |
Output is correct |
11 |
Correct |
910 ms |
18836 KB |
Output is correct |
12 |
Correct |
898 ms |
19092 KB |
Output is correct |
13 |
Correct |
878 ms |
18832 KB |
Output is correct |
14 |
Correct |
909 ms |
18832 KB |
Output is correct |
15 |
Correct |
846 ms |
18832 KB |
Output is correct |
16 |
Correct |
293 ms |
14480 KB |
Output is correct |
17 |
Correct |
301 ms |
14420 KB |
Output is correct |
18 |
Correct |
318 ms |
14416 KB |
Output is correct |
19 |
Correct |
322 ms |
14480 KB |
Output is correct |
20 |
Correct |
315 ms |
14468 KB |
Output is correct |
21 |
Correct |
476 ms |
18768 KB |
Output is correct |
22 |
Correct |
492 ms |
18840 KB |
Output is correct |
23 |
Correct |
471 ms |
18772 KB |
Output is correct |
24 |
Correct |
469 ms |
19028 KB |
Output is correct |
25 |
Correct |
434 ms |
18840 KB |
Output is correct |
26 |
Correct |
488 ms |
18768 KB |
Output is correct |
27 |
Correct |
552 ms |
18836 KB |
Output is correct |
28 |
Correct |
469 ms |
19024 KB |
Output is correct |
29 |
Correct |
506 ms |
18768 KB |
Output is correct |
30 |
Correct |
803 ms |
18828 KB |
Output is correct |
31 |
Correct |
830 ms |
18768 KB |
Output is correct |
32 |
Correct |
874 ms |
18836 KB |
Output is correct |
33 |
Correct |
820 ms |
18840 KB |
Output is correct |
34 |
Correct |
829 ms |
18848 KB |
Output is correct |
35 |
Correct |
829 ms |
18840 KB |
Output is correct |
36 |
Correct |
846 ms |
18844 KB |
Output is correct |
37 |
Correct |
887 ms |
18836 KB |
Output is correct |
38 |
Correct |
884 ms |
18836 KB |
Output is correct |
39 |
Correct |
14 ms |
9308 KB |
Output is correct |
40 |
Correct |
14 ms |
9308 KB |
Output is correct |
41 |
Correct |
14 ms |
9308 KB |
Output is correct |
42 |
Correct |
15 ms |
9360 KB |
Output is correct |
43 |
Correct |
14 ms |
9308 KB |
Output is correct |
44 |
Correct |
15 ms |
9308 KB |
Output is correct |
45 |
Correct |
15 ms |
9308 KB |
Output is correct |
46 |
Correct |
14 ms |
9308 KB |
Output is correct |
47 |
Correct |
14 ms |
9360 KB |
Output is correct |
48 |
Correct |
14 ms |
9356 KB |
Output is correct |
49 |
Correct |
14 ms |
9308 KB |
Output is correct |
50 |
Correct |
13 ms |
9308 KB |
Output is correct |
51 |
Correct |
13 ms |
9364 KB |
Output is correct |
52 |
Correct |
15 ms |
9308 KB |
Output is correct |
53 |
Correct |
14 ms |
9308 KB |
Output is correct |
54 |
Correct |
8 ms |
9352 KB |
Output is correct |
55 |
Correct |
8 ms |
9308 KB |
Output is correct |
56 |
Correct |
8 ms |
9308 KB |
Output is correct |
57 |
Correct |
8 ms |
9304 KB |
Output is correct |
58 |
Correct |
9 ms |
9612 KB |
Output is correct |
59 |
Correct |
1553 ms |
18840 KB |
Output is correct |
60 |
Correct |
1394 ms |
18832 KB |
Output is correct |
61 |
Correct |
1400 ms |
18772 KB |
Output is correct |
62 |
Correct |
1433 ms |
18772 KB |
Output is correct |
63 |
Correct |
1402 ms |
18772 KB |
Output is correct |
64 |
Correct |
1536 ms |
18832 KB |
Output is correct |
65 |
Correct |
1484 ms |
18848 KB |
Output is correct |
66 |
Correct |
1405 ms |
18844 KB |
Output is correct |
67 |
Correct |
1481 ms |
18860 KB |
Output is correct |
68 |
Correct |
1567 ms |
18856 KB |
Output is correct |
69 |
Correct |
1463 ms |
19028 KB |
Output is correct |
70 |
Correct |
1530 ms |
18860 KB |
Output is correct |
71 |
Correct |
1501 ms |
18844 KB |
Output is correct |
72 |
Correct |
1531 ms |
18848 KB |
Output is correct |
73 |
Correct |
1422 ms |
18860 KB |
Output is correct |
74 |
Correct |
330 ms |
14420 KB |
Output is correct |
75 |
Correct |
344 ms |
14496 KB |
Output is correct |
76 |
Correct |
324 ms |
14420 KB |
Output is correct |
77 |
Correct |
333 ms |
14480 KB |
Output is correct |
78 |
Correct |
309 ms |
14480 KB |
Output is correct |