#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int32_t, int32_t> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 510
#define INF (ll)1e9+10
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
int N,A[maxn],B[maxn];
int fac[maxn], invfac[maxn];
int qexp(int a,int b){
int ans = 1;
while (b){
if (b&1) (ans *= a) %= MOD;
(a *= a) %= MOD;
b >>= 1;
}
return ans;
}
int nck(int n,int k){
if (k > n) return 0;
return (((fac[n] * invfac[k]) % MOD) * invfac[n-k]) % MOD;
}
int suffmult[2*maxn][maxn];
int dp[maxn][2*maxn];
int S[2*maxn],E[2*maxn];
int specnck(int x,int k){
//~ cout << E[x]-S[x]+1 << ' ' << k << ' ' << (invfac[k] * suffmult[x][k]) % MOD << '\n';
return (invfac[k] * suffmult[x][k]) % MOD;
}
int f(int x,int y){
int ans = 0;
FOR(z,1,x){
ans += nck(x-1,z-1) * specnck(y,z);
}
return ans;
}
int32_t main(){
cin >> N;
FOR(i,1,N) cin >> A[i] >> B[i];
fac[0] = 1;
FOR(i,1,N) fac[i] = (fac[i-1] * i) % MOD;
invfac[N] = qexp(fac[N], MOD-2);
DEC(i,N-1,0) invfac[i] = (invfac[i+1] * (i+1)) % MOD;
vi v;
FOR(i,1,N){
v.pb(A[i]); v.pb(B[i]);
}
v.pb(0); v.pb(INF);
sort(all(v)); v.erase(unique(all(v)),v.end());
vpi ranges;
unordered_map <int,int> idx;
FOR(i,0,(int)v.size()-1){
idx[v[i]] = ranges.size();
ranges.pb(pi(v[i],1));
if (i + 1 < (int)v.size() && v[i] + 1 < v[i+1]) ranges.pb(pi(i+1,v[i+1]-v[i]-1));
}
FOR(i,0,(int)ranges.size()-1){
S[i] = ranges[i].f; E[i] = ranges[i].f + ranges[i].s - 1;
}
FOR(i,0,(int)ranges.size()-1){
suffmult[i][0] = 1;
int x = E[i] - S[i] + 1;
FOR(j,1,N){
suffmult[i][j] = (suffmult[i][j-1] * x) % MOD;
x--;
}
}
FOR(i,0,(int)ranges.size()-1) dp[N+1][i] = 1;
DEC(i,N,1){
DEC(j,(int)ranges.size()-1,0){
if (B[i] < S[j]){
dp[i][j] = 0; continue;
}
dp[i][j] = dp[i][j+1];
if (A[i] <= S[j] && E[j] <= B[i]){
int num = 1;
FOR(k,i+1,N+1){
(dp[i][j] += (dp[k][j+1] * f(num, j)) % MOD) %= MOD;
if (A[k] <= S[j] && E[j] <= B[k]) num++;
}
}
}
}
int ans = 0;
FOR(i,1,N){
(ans += dp[i][0]) %= MOD;
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8276 KB |
Output is correct |
2 |
Correct |
9 ms |
8380 KB |
Output is correct |
3 |
Correct |
8 ms |
8276 KB |
Output is correct |
4 |
Correct |
8 ms |
8376 KB |
Output is correct |
5 |
Correct |
10 ms |
8276 KB |
Output is correct |
6 |
Correct |
11 ms |
8484 KB |
Output is correct |
7 |
Correct |
12 ms |
8276 KB |
Output is correct |
8 |
Correct |
10 ms |
8408 KB |
Output is correct |
9 |
Correct |
11 ms |
8360 KB |
Output is correct |
10 |
Correct |
9 ms |
8276 KB |
Output is correct |
11 |
Correct |
9 ms |
8276 KB |
Output is correct |
12 |
Correct |
8 ms |
8276 KB |
Output is correct |
13 |
Correct |
11 ms |
8380 KB |
Output is correct |
14 |
Correct |
9 ms |
8276 KB |
Output is correct |
15 |
Correct |
9 ms |
8276 KB |
Output is correct |
16 |
Correct |
5 ms |
3668 KB |
Output is correct |
17 |
Correct |
6 ms |
3980 KB |
Output is correct |
18 |
Correct |
9 ms |
3796 KB |
Output is correct |
19 |
Correct |
8 ms |
3868 KB |
Output is correct |
20 |
Correct |
7 ms |
3840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8276 KB |
Output is correct |
2 |
Correct |
9 ms |
8380 KB |
Output is correct |
3 |
Correct |
8 ms |
8276 KB |
Output is correct |
4 |
Correct |
8 ms |
8376 KB |
Output is correct |
5 |
Correct |
10 ms |
8276 KB |
Output is correct |
6 |
Correct |
11 ms |
8484 KB |
Output is correct |
7 |
Correct |
12 ms |
8276 KB |
Output is correct |
8 |
Correct |
10 ms |
8408 KB |
Output is correct |
9 |
Correct |
11 ms |
8360 KB |
Output is correct |
10 |
Correct |
9 ms |
8276 KB |
Output is correct |
11 |
Correct |
9 ms |
8276 KB |
Output is correct |
12 |
Correct |
8 ms |
8276 KB |
Output is correct |
13 |
Correct |
11 ms |
8380 KB |
Output is correct |
14 |
Correct |
9 ms |
8276 KB |
Output is correct |
15 |
Correct |
9 ms |
8276 KB |
Output is correct |
16 |
Correct |
5 ms |
3668 KB |
Output is correct |
17 |
Correct |
6 ms |
3980 KB |
Output is correct |
18 |
Correct |
9 ms |
3796 KB |
Output is correct |
19 |
Correct |
8 ms |
3868 KB |
Output is correct |
20 |
Correct |
7 ms |
3840 KB |
Output is correct |
21 |
Runtime error |
10 ms |
8788 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8276 KB |
Output is correct |
2 |
Correct |
9 ms |
8380 KB |
Output is correct |
3 |
Correct |
8 ms |
8276 KB |
Output is correct |
4 |
Correct |
8 ms |
8376 KB |
Output is correct |
5 |
Correct |
10 ms |
8276 KB |
Output is correct |
6 |
Correct |
11 ms |
8484 KB |
Output is correct |
7 |
Correct |
12 ms |
8276 KB |
Output is correct |
8 |
Correct |
10 ms |
8408 KB |
Output is correct |
9 |
Correct |
11 ms |
8360 KB |
Output is correct |
10 |
Correct |
9 ms |
8276 KB |
Output is correct |
11 |
Correct |
9 ms |
8276 KB |
Output is correct |
12 |
Correct |
8 ms |
8276 KB |
Output is correct |
13 |
Correct |
11 ms |
8380 KB |
Output is correct |
14 |
Correct |
9 ms |
8276 KB |
Output is correct |
15 |
Correct |
9 ms |
8276 KB |
Output is correct |
16 |
Correct |
5 ms |
3668 KB |
Output is correct |
17 |
Correct |
6 ms |
3980 KB |
Output is correct |
18 |
Correct |
9 ms |
3796 KB |
Output is correct |
19 |
Correct |
8 ms |
3868 KB |
Output is correct |
20 |
Correct |
7 ms |
3840 KB |
Output is correct |
21 |
Runtime error |
10 ms |
8788 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |