#include<bits/stdc++.h>
using namespace std;
const int N=510, mod=1e9+7;
int fact[N*2], invfact[N*2];
int binpow(int x, int y){
int t=1;
while (y){
if (y&1) t=1ll*t*x%mod;
x=1ll*x*x%mod;
y>>=1;
}
return t;
}
void precalc(){
fact[0]=1;
for (int i=1; i<N*2; ++i) fact[i]=1ll*fact[i-1]*i%mod;
invfact[N*2-1]=binpow(fact[N*2-1], mod-2);
for (int i=N*2-2; i>=0; --i) invfact[i]=1ll*invfact[i+1]*(i+1)%mod;
}
int C(int n, int k){
if (n<0 || k<0 || n<k) return 0;
return 1ll*fact[n]*invfact[k]%mod*invfact[n-k]%mod;
}
int f[N][N*2], n, a[N], b[N];
vector<int> vals;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
precalc();
vals.push_back(-1);
cin >> n;
for (int i=1; i<=n; ++i) cin >> a[i] >> b[i], vals.push_back(a[i]), vals.push_back(++b[i]);
sort(vals.begin(), vals.end());
vals.resize(unique(vals.begin(), vals.end())-vals.begin());
for (int i=1; i<=n; ++i){
a[i]=lower_bound(vals.begin(), vals.end(), a[i])-vals.begin();
b[i]=lower_bound(vals.begin(), vals.end(), b[i])-vals.begin();
}
for (int i=0; i<(int)vals.size(); ++i) f[0][i]=1;
for (int i=1; i<=n; ++i){
for (int j=a[i]; j<b[i]; ++j){
f[i][j]=f[i][j-1];
for (int k=i-1; k>=0; --k){
f[i][j]=(f[i][j]+1ll*f[k][j-1]*C(vals[j+1]-vals[j], i-k))%mod;
if (j<a[k] || b[k]<=j) break;
}
}
for (int j=b[i]; j<(int)vals.size(); ++j) f[i][j]=f[i][j-1];
for (int j=0; j<(int)vals.size(); ++j) f[i][j]=(f[i][j]+f[i-1][j])%mod;
}
cout << (f[n][(int)vals.size()-1]+mod-1)%mod << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2392 KB |
Output is correct |
2 |
Correct |
3 ms |
2396 KB |
Output is correct |
3 |
Correct |
3 ms |
2396 KB |
Output is correct |
4 |
Correct |
3 ms |
2444 KB |
Output is correct |
5 |
Correct |
3 ms |
2648 KB |
Output is correct |
6 |
Correct |
3 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2392 KB |
Output is correct |
8 |
Correct |
3 ms |
2396 KB |
Output is correct |
9 |
Correct |
3 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2488 KB |
Output is correct |
11 |
Correct |
2 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
3 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2392 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
2 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2272 KB |
Output is correct |
20 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2392 KB |
Output is correct |
2 |
Correct |
3 ms |
2396 KB |
Output is correct |
3 |
Correct |
3 ms |
2396 KB |
Output is correct |
4 |
Correct |
3 ms |
2444 KB |
Output is correct |
5 |
Correct |
3 ms |
2648 KB |
Output is correct |
6 |
Correct |
3 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2392 KB |
Output is correct |
8 |
Correct |
3 ms |
2396 KB |
Output is correct |
9 |
Correct |
3 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2488 KB |
Output is correct |
11 |
Correct |
2 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
3 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2392 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
2 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2272 KB |
Output is correct |
20 |
Correct |
2 ms |
2396 KB |
Output is correct |
21 |
Incorrect |
4 ms |
2396 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2392 KB |
Output is correct |
2 |
Correct |
3 ms |
2396 KB |
Output is correct |
3 |
Correct |
3 ms |
2396 KB |
Output is correct |
4 |
Correct |
3 ms |
2444 KB |
Output is correct |
5 |
Correct |
3 ms |
2648 KB |
Output is correct |
6 |
Correct |
3 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2392 KB |
Output is correct |
8 |
Correct |
3 ms |
2396 KB |
Output is correct |
9 |
Correct |
3 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2488 KB |
Output is correct |
11 |
Correct |
2 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
3 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2392 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
2 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2272 KB |
Output is correct |
20 |
Correct |
2 ms |
2396 KB |
Output is correct |
21 |
Incorrect |
4 ms |
2396 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |