#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
const ll mod=1e9+7,N=5e2+5;
ll binpow(ll a,ll b){
ll res=1;
while(b){
if(b&1){
res=res*a%mod;
}
a=a*a%mod;
b=b>>1;
}
return res;
}
ll inv(ll a){
return binpow(a,mod-2);
}
ll fact[N],invfact[N],C[2*N][N];
vector<ll>v;
void init(){
fact[0]=1;
for(ll i=1;i<N;i++){
fact[i]=fact[i-1]*i%mod;
}
invfact[N-1]=inv(fact[N-1]);
for(ll i=N-1;i>=1;i--){
invfact[i-1]=invfact[i]*i%mod;
}
for(ll i=0;i<v.size();i++){
ll cur=1,L=1,R=v[i];
for(ll j=1;j<N;j++){
if(j>v[i]){
cur=0;
}
else{
cur=cur*R%mod*inv(L)%mod;
R--;
L++;
}
C[i+1][j]=cur;
}
}
}
ll nCk(ll i,ll k){
return C[i][k];
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n;
cin>>n;
ll a[n+5],b[n+5];
set<ll>s;
for(ll i=1;i<=n;i++){
cin>>a[i]>>b[i];
s.insert(a[i]);
s.insert(b[i]+1);
}
ll cur=0;
ll l[2*n+5];
for(auto x:s){
cur++;
l[cur]=x;
}
for(ll i=1;i<cur;i++){
v.pb(l[i+1]-l[i]);
}
init();
ll dp[2*n+5][n+5],sum[2*n+5][n+5];
memset(sum,0,sizeof sum);
ll ans=0;
for(ll i=1;i<=n;i++){
ll tot=1;
memset(dp,0,sizeof dp);
for(ll j=1;j<cur;j++){//l[j] l[j+1]-1
if(b[i]>=l[j]&&a[i]<l[j+1]){
dp[j][1]=tot;
for(ll k=2;k<=n;k++){
dp[j][k]=sum[j][k-1];
}
}
for(ll k=1;k<=n;k++){
tot+=sum[j][k]*nCk(j,k)%mod;
tot%=mod;
}
for(ll k=1;k<=n;k++){
sum[j][k]+=dp[j][k];
sum[j][k]%=mod;
}
}
}
for(ll j=1;j<cur;j++){
for(ll k=1;k<=n;k++){
ans+=sum[j][k]*nCk(j,k)%mod;
ans%=mod;
}
}
cout<<ans;
}
Compilation message
boat.cpp: In function 'void init()':
boat.cpp:42:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(ll i=0;i<v.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1363 ms |
12420 KB |
Output is correct |
2 |
Correct |
1370 ms |
12680 KB |
Output is correct |
3 |
Correct |
1369 ms |
12428 KB |
Output is correct |
4 |
Correct |
1367 ms |
12624 KB |
Output is correct |
5 |
Correct |
1371 ms |
12432 KB |
Output is correct |
6 |
Correct |
1366 ms |
12428 KB |
Output is correct |
7 |
Correct |
1381 ms |
12432 KB |
Output is correct |
8 |
Correct |
1378 ms |
12428 KB |
Output is correct |
9 |
Correct |
1364 ms |
12436 KB |
Output is correct |
10 |
Correct |
1385 ms |
12432 KB |
Output is correct |
11 |
Correct |
1357 ms |
12428 KB |
Output is correct |
12 |
Correct |
1358 ms |
12432 KB |
Output is correct |
13 |
Correct |
1374 ms |
12432 KB |
Output is correct |
14 |
Correct |
1352 ms |
12428 KB |
Output is correct |
15 |
Correct |
1365 ms |
12428 KB |
Output is correct |
16 |
Correct |
279 ms |
10652 KB |
Output is correct |
17 |
Correct |
290 ms |
10832 KB |
Output is correct |
18 |
Correct |
292 ms |
10656 KB |
Output is correct |
19 |
Correct |
296 ms |
10652 KB |
Output is correct |
20 |
Correct |
283 ms |
10652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1363 ms |
12420 KB |
Output is correct |
2 |
Correct |
1370 ms |
12680 KB |
Output is correct |
3 |
Correct |
1369 ms |
12428 KB |
Output is correct |
4 |
Correct |
1367 ms |
12624 KB |
Output is correct |
5 |
Correct |
1371 ms |
12432 KB |
Output is correct |
6 |
Correct |
1366 ms |
12428 KB |
Output is correct |
7 |
Correct |
1381 ms |
12432 KB |
Output is correct |
8 |
Correct |
1378 ms |
12428 KB |
Output is correct |
9 |
Correct |
1364 ms |
12436 KB |
Output is correct |
10 |
Correct |
1385 ms |
12432 KB |
Output is correct |
11 |
Correct |
1357 ms |
12428 KB |
Output is correct |
12 |
Correct |
1358 ms |
12432 KB |
Output is correct |
13 |
Correct |
1374 ms |
12432 KB |
Output is correct |
14 |
Correct |
1352 ms |
12428 KB |
Output is correct |
15 |
Correct |
1365 ms |
12428 KB |
Output is correct |
16 |
Correct |
279 ms |
10652 KB |
Output is correct |
17 |
Correct |
290 ms |
10832 KB |
Output is correct |
18 |
Correct |
292 ms |
10656 KB |
Output is correct |
19 |
Correct |
296 ms |
10652 KB |
Output is correct |
20 |
Correct |
283 ms |
10652 KB |
Output is correct |
21 |
Correct |
1296 ms |
12068 KB |
Output is correct |
22 |
Correct |
1279 ms |
12368 KB |
Output is correct |
23 |
Correct |
1297 ms |
12052 KB |
Output is correct |
24 |
Correct |
1248 ms |
12116 KB |
Output is correct |
25 |
Correct |
1256 ms |
12044 KB |
Output is correct |
26 |
Correct |
1226 ms |
11948 KB |
Output is correct |
27 |
Correct |
1315 ms |
12004 KB |
Output is correct |
28 |
Correct |
1294 ms |
11940 KB |
Output is correct |
29 |
Correct |
1304 ms |
11928 KB |
Output is correct |
30 |
Correct |
1400 ms |
12416 KB |
Output is correct |
31 |
Correct |
1357 ms |
12624 KB |
Output is correct |
32 |
Correct |
1366 ms |
12424 KB |
Output is correct |
33 |
Correct |
1381 ms |
12428 KB |
Output is correct |
34 |
Correct |
1384 ms |
12416 KB |
Output is correct |
35 |
Correct |
1380 ms |
12408 KB |
Output is correct |
36 |
Correct |
1370 ms |
12620 KB |
Output is correct |
37 |
Correct |
1352 ms |
12428 KB |
Output is correct |
38 |
Correct |
1408 ms |
12628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
2904 KB |
Output is correct |
2 |
Correct |
23 ms |
2904 KB |
Output is correct |
3 |
Correct |
23 ms |
2908 KB |
Output is correct |
4 |
Correct |
23 ms |
2908 KB |
Output is correct |
5 |
Correct |
23 ms |
3160 KB |
Output is correct |
6 |
Correct |
24 ms |
2904 KB |
Output is correct |
7 |
Correct |
23 ms |
2904 KB |
Output is correct |
8 |
Correct |
23 ms |
2904 KB |
Output is correct |
9 |
Correct |
24 ms |
3164 KB |
Output is correct |
10 |
Correct |
24 ms |
2904 KB |
Output is correct |
11 |
Correct |
24 ms |
2908 KB |
Output is correct |
12 |
Correct |
23 ms |
2908 KB |
Output is correct |
13 |
Correct |
23 ms |
2908 KB |
Output is correct |
14 |
Correct |
23 ms |
2964 KB |
Output is correct |
15 |
Correct |
23 ms |
2908 KB |
Output is correct |
16 |
Correct |
12 ms |
2908 KB |
Output is correct |
17 |
Correct |
13 ms |
2908 KB |
Output is correct |
18 |
Correct |
13 ms |
3036 KB |
Output is correct |
19 |
Correct |
12 ms |
2908 KB |
Output is correct |
20 |
Correct |
12 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1363 ms |
12420 KB |
Output is correct |
2 |
Correct |
1370 ms |
12680 KB |
Output is correct |
3 |
Correct |
1369 ms |
12428 KB |
Output is correct |
4 |
Correct |
1367 ms |
12624 KB |
Output is correct |
5 |
Correct |
1371 ms |
12432 KB |
Output is correct |
6 |
Correct |
1366 ms |
12428 KB |
Output is correct |
7 |
Correct |
1381 ms |
12432 KB |
Output is correct |
8 |
Correct |
1378 ms |
12428 KB |
Output is correct |
9 |
Correct |
1364 ms |
12436 KB |
Output is correct |
10 |
Correct |
1385 ms |
12432 KB |
Output is correct |
11 |
Correct |
1357 ms |
12428 KB |
Output is correct |
12 |
Correct |
1358 ms |
12432 KB |
Output is correct |
13 |
Correct |
1374 ms |
12432 KB |
Output is correct |
14 |
Correct |
1352 ms |
12428 KB |
Output is correct |
15 |
Correct |
1365 ms |
12428 KB |
Output is correct |
16 |
Correct |
279 ms |
10652 KB |
Output is correct |
17 |
Correct |
290 ms |
10832 KB |
Output is correct |
18 |
Correct |
292 ms |
10656 KB |
Output is correct |
19 |
Correct |
296 ms |
10652 KB |
Output is correct |
20 |
Correct |
283 ms |
10652 KB |
Output is correct |
21 |
Correct |
1296 ms |
12068 KB |
Output is correct |
22 |
Correct |
1279 ms |
12368 KB |
Output is correct |
23 |
Correct |
1297 ms |
12052 KB |
Output is correct |
24 |
Correct |
1248 ms |
12116 KB |
Output is correct |
25 |
Correct |
1256 ms |
12044 KB |
Output is correct |
26 |
Correct |
1226 ms |
11948 KB |
Output is correct |
27 |
Correct |
1315 ms |
12004 KB |
Output is correct |
28 |
Correct |
1294 ms |
11940 KB |
Output is correct |
29 |
Correct |
1304 ms |
11928 KB |
Output is correct |
30 |
Correct |
1400 ms |
12416 KB |
Output is correct |
31 |
Correct |
1357 ms |
12624 KB |
Output is correct |
32 |
Correct |
1366 ms |
12424 KB |
Output is correct |
33 |
Correct |
1381 ms |
12428 KB |
Output is correct |
34 |
Correct |
1384 ms |
12416 KB |
Output is correct |
35 |
Correct |
1380 ms |
12408 KB |
Output is correct |
36 |
Correct |
1370 ms |
12620 KB |
Output is correct |
37 |
Correct |
1352 ms |
12428 KB |
Output is correct |
38 |
Correct |
1408 ms |
12628 KB |
Output is correct |
39 |
Correct |
24 ms |
2904 KB |
Output is correct |
40 |
Correct |
23 ms |
2904 KB |
Output is correct |
41 |
Correct |
23 ms |
2908 KB |
Output is correct |
42 |
Correct |
23 ms |
2908 KB |
Output is correct |
43 |
Correct |
23 ms |
3160 KB |
Output is correct |
44 |
Correct |
24 ms |
2904 KB |
Output is correct |
45 |
Correct |
23 ms |
2904 KB |
Output is correct |
46 |
Correct |
23 ms |
2904 KB |
Output is correct |
47 |
Correct |
24 ms |
3164 KB |
Output is correct |
48 |
Correct |
24 ms |
2904 KB |
Output is correct |
49 |
Correct |
24 ms |
2908 KB |
Output is correct |
50 |
Correct |
23 ms |
2908 KB |
Output is correct |
51 |
Correct |
23 ms |
2908 KB |
Output is correct |
52 |
Correct |
23 ms |
2964 KB |
Output is correct |
53 |
Correct |
23 ms |
2908 KB |
Output is correct |
54 |
Correct |
12 ms |
2908 KB |
Output is correct |
55 |
Correct |
13 ms |
2908 KB |
Output is correct |
56 |
Correct |
13 ms |
3036 KB |
Output is correct |
57 |
Correct |
12 ms |
2908 KB |
Output is correct |
58 |
Correct |
12 ms |
2908 KB |
Output is correct |
59 |
Correct |
1452 ms |
12616 KB |
Output is correct |
60 |
Correct |
1441 ms |
12596 KB |
Output is correct |
61 |
Correct |
1462 ms |
12428 KB |
Output is correct |
62 |
Correct |
1497 ms |
12424 KB |
Output is correct |
63 |
Correct |
1575 ms |
12432 KB |
Output is correct |
64 |
Correct |
1483 ms |
12428 KB |
Output is correct |
65 |
Correct |
1476 ms |
12428 KB |
Output is correct |
66 |
Correct |
1462 ms |
12432 KB |
Output is correct |
67 |
Correct |
1564 ms |
12424 KB |
Output is correct |
68 |
Correct |
1513 ms |
12428 KB |
Output is correct |
69 |
Correct |
1444 ms |
12424 KB |
Output is correct |
70 |
Correct |
1425 ms |
12428 KB |
Output is correct |
71 |
Correct |
1438 ms |
12624 KB |
Output is correct |
72 |
Correct |
1442 ms |
12428 KB |
Output is correct |
73 |
Correct |
1476 ms |
12424 KB |
Output is correct |
74 |
Correct |
284 ms |
10656 KB |
Output is correct |
75 |
Correct |
289 ms |
10656 KB |
Output is correct |
76 |
Correct |
283 ms |
10588 KB |
Output is correct |
77 |
Correct |
288 ms |
10656 KB |
Output is correct |
78 |
Correct |
284 ms |
10652 KB |
Output is correct |