#include<bits/stdc++.h>
#define lf double
#define ll long long
#define cc pair<char,char>
#define ull unsigned ll
#define ii pair<int,int>
#define li pair<ll,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define iiii2 pair<int,iii>
#define lii pair<ll,ii>
#define lolo pair<ll,ll>
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define umin(x,y) x=min(x,y)
#define umax(x,y) x=max(x,y)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define MOD 1000000007
#define inf 100000000
#define M 10000002
#define N 1005
#define LOG 20
#define magic 100
#define KOK 250
#define EPS 0.0025
#define pw(x) ((1ll)<<(x))
#define PI 3.1415926535
using namespace std;
int n,cev;
int a[N],b[N],dp[N][N],inv[N];
vector<ii> seg,e;
int add(int x,int y) {
x+=y;
while(x<0) x+=MOD;
while(x>=MOD) x-=MOD;
return x;
}
int mul(int x,int y) {
return 1ll*x*y%MOD;
}
int fe(int x,int y) {
if(y==0) return 1;
if(y==1) return x;
int res=fe(x,y/2);
res=mul(res,res);
if(y&1) res=mul(res,x);
return res;
}
int main() {
#if 0
freopen("input.txt","r",stdin);
#endif
for(int i=1;i<N;i++) {
inv[i]=fe(i,MOD-2);
}
scanf("%d",&n);
for(int i=1;i<=n;i++) {
scanf("%d %d",&a[i],&b[i]);
e.pb({a[i],0});
e.pb({b[i],1});
}
sort(all(e));
seg.pb({-inf,e[0].st-1});
for(int i=0;i<sz(e)-1;i++) {
int x=e[i].st+e[i].nd,y=e[i+1].st-!e[i+1].nd;
if(x>y) continue ;
seg.pb({x,y});
}
seg.pb({e.back().st+1,inf});
//for(auto ss:seg) printf("%d %d\n",ss.st,ss.nd);
for(int i=0;i<sz(seg);i++) dp[0][i]=1;
for(int i=1;i<=n;i++) {
int flag=0;
for(int now=0;now<sz(seg);now++) {
ii rng=seg[now];
if(rng.st>b[i] || rng.nd<a[i]) {
if(now) {
dp[i][now]=dp[i][now-1];
}
continue ;
}
int tot=0;
int sz=rng.nd-rng.st+1;
int res=sz;
int ans=0;
for(int j=i-1;j>=0;j--) {
ans=add(ans,mul(res,dp[j][now-1]));
if(rng.st>=a[j] && rng.nd<=b[j]) {
tot++;
res=mul(res,sz+tot);
res=mul(res,inv[tot+1]);
}
}
cev=add(cev,ans);
dp[i][now]=add(dp[i][now-1],ans);
//printf("RESULT : %d %d %d\n",i,now,ans);
}
}
printf("%d",cev);
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:124:7: warning: unused variable 'flag' [-Wunused-variable]
int flag=0;
^~~~
boat.cpp:91:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
boat.cpp:95:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&a[i],&b[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2296 KB |
Output is correct |
2 |
Correct |
6 ms |
2404 KB |
Output is correct |
3 |
Correct |
6 ms |
2480 KB |
Output is correct |
4 |
Correct |
7 ms |
2668 KB |
Output is correct |
5 |
Correct |
7 ms |
2668 KB |
Output is correct |
6 |
Correct |
7 ms |
2668 KB |
Output is correct |
7 |
Correct |
9 ms |
2668 KB |
Output is correct |
8 |
Correct |
7 ms |
2668 KB |
Output is correct |
9 |
Correct |
7 ms |
2668 KB |
Output is correct |
10 |
Correct |
7 ms |
2668 KB |
Output is correct |
11 |
Correct |
8 ms |
2668 KB |
Output is correct |
12 |
Correct |
8 ms |
2668 KB |
Output is correct |
13 |
Correct |
8 ms |
2668 KB |
Output is correct |
14 |
Correct |
6 ms |
2668 KB |
Output is correct |
15 |
Correct |
6 ms |
2668 KB |
Output is correct |
16 |
Correct |
6 ms |
2668 KB |
Output is correct |
17 |
Correct |
7 ms |
2668 KB |
Output is correct |
18 |
Correct |
6 ms |
2668 KB |
Output is correct |
19 |
Correct |
6 ms |
2668 KB |
Output is correct |
20 |
Correct |
6 ms |
2668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2296 KB |
Output is correct |
2 |
Correct |
6 ms |
2404 KB |
Output is correct |
3 |
Correct |
6 ms |
2480 KB |
Output is correct |
4 |
Correct |
7 ms |
2668 KB |
Output is correct |
5 |
Correct |
7 ms |
2668 KB |
Output is correct |
6 |
Correct |
7 ms |
2668 KB |
Output is correct |
7 |
Correct |
9 ms |
2668 KB |
Output is correct |
8 |
Correct |
7 ms |
2668 KB |
Output is correct |
9 |
Correct |
7 ms |
2668 KB |
Output is correct |
10 |
Correct |
7 ms |
2668 KB |
Output is correct |
11 |
Correct |
8 ms |
2668 KB |
Output is correct |
12 |
Correct |
8 ms |
2668 KB |
Output is correct |
13 |
Correct |
8 ms |
2668 KB |
Output is correct |
14 |
Correct |
6 ms |
2668 KB |
Output is correct |
15 |
Correct |
6 ms |
2668 KB |
Output is correct |
16 |
Correct |
6 ms |
2668 KB |
Output is correct |
17 |
Correct |
7 ms |
2668 KB |
Output is correct |
18 |
Correct |
6 ms |
2668 KB |
Output is correct |
19 |
Correct |
6 ms |
2668 KB |
Output is correct |
20 |
Correct |
6 ms |
2668 KB |
Output is correct |
21 |
Correct |
803 ms |
2700 KB |
Output is correct |
22 |
Correct |
731 ms |
2700 KB |
Output is correct |
23 |
Correct |
686 ms |
2700 KB |
Output is correct |
24 |
Correct |
750 ms |
2700 KB |
Output is correct |
25 |
Correct |
752 ms |
2764 KB |
Output is correct |
26 |
Correct |
1119 ms |
2940 KB |
Output is correct |
27 |
Correct |
1183 ms |
2940 KB |
Output is correct |
28 |
Correct |
1128 ms |
2940 KB |
Output is correct |
29 |
Correct |
1089 ms |
2940 KB |
Output is correct |
30 |
Correct |
13 ms |
2940 KB |
Output is correct |
31 |
Correct |
11 ms |
2940 KB |
Output is correct |
32 |
Correct |
12 ms |
2940 KB |
Output is correct |
33 |
Correct |
11 ms |
2940 KB |
Output is correct |
34 |
Correct |
11 ms |
2940 KB |
Output is correct |
35 |
Correct |
15 ms |
2940 KB |
Output is correct |
36 |
Correct |
13 ms |
2940 KB |
Output is correct |
37 |
Correct |
16 ms |
2940 KB |
Output is correct |
38 |
Correct |
13 ms |
2940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2940 KB |
Output is correct |
2 |
Correct |
7 ms |
2940 KB |
Output is correct |
3 |
Correct |
7 ms |
2940 KB |
Output is correct |
4 |
Correct |
8 ms |
2940 KB |
Output is correct |
5 |
Correct |
9 ms |
2940 KB |
Output is correct |
6 |
Correct |
12 ms |
2940 KB |
Output is correct |
7 |
Correct |
12 ms |
2940 KB |
Output is correct |
8 |
Correct |
12 ms |
2940 KB |
Output is correct |
9 |
Correct |
12 ms |
2940 KB |
Output is correct |
10 |
Correct |
12 ms |
2940 KB |
Output is correct |
11 |
Correct |
8 ms |
2940 KB |
Output is correct |
12 |
Correct |
7 ms |
2940 KB |
Output is correct |
13 |
Correct |
7 ms |
2940 KB |
Output is correct |
14 |
Correct |
8 ms |
2940 KB |
Output is correct |
15 |
Correct |
9 ms |
2940 KB |
Output is correct |
16 |
Correct |
6 ms |
2940 KB |
Output is correct |
17 |
Correct |
7 ms |
2940 KB |
Output is correct |
18 |
Correct |
7 ms |
2940 KB |
Output is correct |
19 |
Correct |
6 ms |
2940 KB |
Output is correct |
20 |
Correct |
6 ms |
2940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2296 KB |
Output is correct |
2 |
Correct |
6 ms |
2404 KB |
Output is correct |
3 |
Correct |
6 ms |
2480 KB |
Output is correct |
4 |
Correct |
7 ms |
2668 KB |
Output is correct |
5 |
Correct |
7 ms |
2668 KB |
Output is correct |
6 |
Correct |
7 ms |
2668 KB |
Output is correct |
7 |
Correct |
9 ms |
2668 KB |
Output is correct |
8 |
Correct |
7 ms |
2668 KB |
Output is correct |
9 |
Correct |
7 ms |
2668 KB |
Output is correct |
10 |
Correct |
7 ms |
2668 KB |
Output is correct |
11 |
Correct |
8 ms |
2668 KB |
Output is correct |
12 |
Correct |
8 ms |
2668 KB |
Output is correct |
13 |
Correct |
8 ms |
2668 KB |
Output is correct |
14 |
Correct |
6 ms |
2668 KB |
Output is correct |
15 |
Correct |
6 ms |
2668 KB |
Output is correct |
16 |
Correct |
6 ms |
2668 KB |
Output is correct |
17 |
Correct |
7 ms |
2668 KB |
Output is correct |
18 |
Correct |
6 ms |
2668 KB |
Output is correct |
19 |
Correct |
6 ms |
2668 KB |
Output is correct |
20 |
Correct |
6 ms |
2668 KB |
Output is correct |
21 |
Correct |
803 ms |
2700 KB |
Output is correct |
22 |
Correct |
731 ms |
2700 KB |
Output is correct |
23 |
Correct |
686 ms |
2700 KB |
Output is correct |
24 |
Correct |
750 ms |
2700 KB |
Output is correct |
25 |
Correct |
752 ms |
2764 KB |
Output is correct |
26 |
Correct |
1119 ms |
2940 KB |
Output is correct |
27 |
Correct |
1183 ms |
2940 KB |
Output is correct |
28 |
Correct |
1128 ms |
2940 KB |
Output is correct |
29 |
Correct |
1089 ms |
2940 KB |
Output is correct |
30 |
Correct |
13 ms |
2940 KB |
Output is correct |
31 |
Correct |
11 ms |
2940 KB |
Output is correct |
32 |
Correct |
12 ms |
2940 KB |
Output is correct |
33 |
Correct |
11 ms |
2940 KB |
Output is correct |
34 |
Correct |
11 ms |
2940 KB |
Output is correct |
35 |
Correct |
15 ms |
2940 KB |
Output is correct |
36 |
Correct |
13 ms |
2940 KB |
Output is correct |
37 |
Correct |
16 ms |
2940 KB |
Output is correct |
38 |
Correct |
13 ms |
2940 KB |
Output is correct |
39 |
Correct |
9 ms |
2940 KB |
Output is correct |
40 |
Correct |
7 ms |
2940 KB |
Output is correct |
41 |
Correct |
7 ms |
2940 KB |
Output is correct |
42 |
Correct |
8 ms |
2940 KB |
Output is correct |
43 |
Correct |
9 ms |
2940 KB |
Output is correct |
44 |
Correct |
12 ms |
2940 KB |
Output is correct |
45 |
Correct |
12 ms |
2940 KB |
Output is correct |
46 |
Correct |
12 ms |
2940 KB |
Output is correct |
47 |
Correct |
12 ms |
2940 KB |
Output is correct |
48 |
Correct |
12 ms |
2940 KB |
Output is correct |
49 |
Correct |
8 ms |
2940 KB |
Output is correct |
50 |
Correct |
7 ms |
2940 KB |
Output is correct |
51 |
Correct |
7 ms |
2940 KB |
Output is correct |
52 |
Correct |
8 ms |
2940 KB |
Output is correct |
53 |
Correct |
9 ms |
2940 KB |
Output is correct |
54 |
Correct |
6 ms |
2940 KB |
Output is correct |
55 |
Correct |
7 ms |
2940 KB |
Output is correct |
56 |
Correct |
7 ms |
2940 KB |
Output is correct |
57 |
Correct |
6 ms |
2940 KB |
Output is correct |
58 |
Correct |
6 ms |
2940 KB |
Output is correct |
59 |
Correct |
787 ms |
3016 KB |
Output is correct |
60 |
Correct |
700 ms |
3060 KB |
Output is correct |
61 |
Correct |
646 ms |
3060 KB |
Output is correct |
62 |
Correct |
757 ms |
3276 KB |
Output is correct |
63 |
Correct |
849 ms |
3276 KB |
Output is correct |
64 |
Correct |
1264 ms |
3276 KB |
Output is correct |
65 |
Correct |
1256 ms |
3276 KB |
Output is correct |
66 |
Correct |
1260 ms |
3276 KB |
Output is correct |
67 |
Correct |
1179 ms |
3276 KB |
Output is correct |
68 |
Correct |
1296 ms |
3276 KB |
Output is correct |
69 |
Correct |
712 ms |
3304 KB |
Output is correct |
70 |
Correct |
656 ms |
3304 KB |
Output is correct |
71 |
Correct |
654 ms |
3304 KB |
Output is correct |
72 |
Correct |
691 ms |
3304 KB |
Output is correct |
73 |
Correct |
720 ms |
3304 KB |
Output is correct |
74 |
Correct |
154 ms |
3304 KB |
Output is correct |
75 |
Correct |
148 ms |
3304 KB |
Output is correct |
76 |
Correct |
144 ms |
3304 KB |
Output is correct |
77 |
Correct |
141 ms |
3304 KB |
Output is correct |
78 |
Correct |
148 ms |
3304 KB |
Output is correct |