#include "bits/stdc++.h"
using namespace std;
#define ar array
const int mod = 1e9 + 7;
int bp(int a, int b){
int r=1;
while(b){
if(b&1) r = r * 1ll * a % mod;
a = a * 1ll * a % mod; b >>= 1;
} return r;
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
vector<int> a(2 * n), p(2 * n), og;
iota(p.begin(), p.end(), 0);
for(int i=0;i<n;i++){
cin>>a[i<<1]>>a[i<<1|1];
a[i<<1|1]++;
}
sort(p.begin(), p.end(), [&](int i, int j){
return (a[i] < a[j]);
});
int last=0;
for(int i=0, j=0;i<n+n;last++){
while(j<n+n && a[p[j]] == a[p[i]]) j++;
og.push_back(a[p[i]]);
while(i < j) a[p[i]] = last, i++;
}
vector<int> f(n + 1), inv(n + 1);
f[0] = inv[0] = 1;
for(int i=1;i<=n;i++){
f[i] = f[i-1] * 1ll * i % mod;
inv[i] = bp(f[i], mod - 2);
}
auto C = [&](int n, int k){
if(n < k) return 0ll;
return f[n] * 1ll * inv[k] % mod * inv[n - k] % mod;
};
int res = 0;
vector<vector<int>> dp(n, vector<int>(last));
for(int i=0;i<n;i++){
int l = a[i<<1], r = a[i<<1|1];
for(int k=l;k<r;k++){
assert(k+1 < last);
int c=1, x=og[k+1] - og[k];
for(int j=i-1;~j;j--){
dp[i][k] = (dp[i][k] + (k ? dp[j][k-1] : 0) * 1ll * C(c + x - 1, c - 1)) % mod;
}
dp[i][k] = (dp[i][k] + C(c + x - 1, c - 1)) % mod;
if(k) dp[i][k] = (dp[i][k] + dp[i][k-1]) % mod;
}
res = (res + dp[i][r-1]) % mod;
//~ for(int k=0;k<last;k++) cout<<dp[i][k]<<" ";
//~ cout<<"\n";
}
cout<<res<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |