Submission #42628

# Submission time Handle Problem Language Result Execution time Memory
42628 2018-03-01T14:33:20 Z fefe Boat (APIO16_boat) C++14
100 / 100
1070 ms 1440 KB
#include<bits/stdc++.h>
#define MAX_N 505
#define mod 1000000007LL
#define pb push_back
typedef long long LL;
using namespace std;
struct node{
	LL s,e;
}arr[MAX_N];
LL n,ans,inv[10*MAX_N];
LL t[MAX_N],sum[MAX_N],ss[MAX_N];
vector<LL> X,lst;
LL Pow(LL x,LL y){
	if(y==0)	return 1;
	if(y==1)	return x;
	LL z=Pow(x,y/2);
	z*=z;z%=mod;
	if(y%2)	z*=x;
	z%=mod;
	return z;
}
int main(){
	LL i,j,k,s,e,x,y,S,E,cnt,p;
	scanf("%lld",&n);
	for(i=1;i<=n;i++){
		scanf("%lld %lld",&arr[i].s,&arr[i].e);
		arr[i].e++;
		X.pb(arr[i].s);X.pb(arr[i].e);
	}
	for(i=1;i<=2000;i++)	inv[i]=Pow(i,mod-2);
	sort(X.begin(),X.end());X.erase(unique(X.begin(),X.end()),X.end());
	LL sz=X.size();
	ss[0]=1;
	for(i=0;i<=n;i++)	sum[i]=1;
	for(i=1;i<sz;i++){
		s=X[i-1];
		e=X[i];
		lst.resize(0);
		sum[0]=1;
		for(j=1;j<=n;j++){
			if(arr[j].e>=e && arr[j].s<=s)	lst.pb(j);
		}
		p=e-s;
		y=lst.size();
		for(j=0;j<y;j++)	t[j]=(p*sum[lst[j]-1]+(j?t[j-1]:0))%mod;
		for(k=0;k<y;k++)	ss[lst[k]]=(ss[lst[k]]+t[k]-(k?t[k-1]:0)+mod)%mod;
		for(j=2;j<=y && j<=p;j++){
			for(k=y-1;k>=j-1;k--)	t[k]=((t[k-1]*(p-j+1))%mod*inv[j])%mod;
			for(k=0;k<j-1;k++)	t[k]=0;
			for(k=0;k<y;k++)	t[k]=(t[k]+(j?t[k-1]:0))%mod;
			for(k=0;k<y;k++)	ss[lst[k]]=(ss[lst[k]]+t[k]-(k?t[k-1]:0)+mod)%mod;
		}
		x=0;
		sum[0]=1;
		for(j=1;j<=n;j++){
			sum[j]=(sum[j-1]+ss[j])%mod;
		}
	}
	printf("%lld\n",(sum[n]-1+mod)%mod);
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:23:15: warning: variable 'x' set but not used [-Wunused-but-set-variable]
  LL i,j,k,s,e,x,y,S,E,cnt,p;
               ^
boat.cpp:23:19: warning: unused variable 'S' [-Wunused-variable]
  LL i,j,k,s,e,x,y,S,E,cnt,p;
                   ^
boat.cpp:23:21: warning: unused variable 'E' [-Wunused-variable]
  LL i,j,k,s,e,x,y,S,E,cnt,p;
                     ^
boat.cpp:23:23: warning: unused variable 'cnt' [-Wunused-variable]
  LL i,j,k,s,e,x,y,S,E,cnt,p;
                       ^
boat.cpp:24:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
                  ^
boat.cpp:26:41: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld",&arr[i].s,&arr[i].e);
                                         ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 8 ms 480 KB Output is correct
3 Correct 7 ms 480 KB Output is correct
4 Correct 8 ms 492 KB Output is correct
5 Correct 8 ms 624 KB Output is correct
6 Correct 6 ms 624 KB Output is correct
7 Correct 7 ms 624 KB Output is correct
8 Correct 6 ms 636 KB Output is correct
9 Correct 7 ms 636 KB Output is correct
10 Correct 7 ms 636 KB Output is correct
11 Correct 6 ms 636 KB Output is correct
12 Correct 7 ms 712 KB Output is correct
13 Correct 6 ms 712 KB Output is correct
14 Correct 7 ms 712 KB Output is correct
15 Correct 7 ms 712 KB Output is correct
16 Correct 4 ms 712 KB Output is correct
17 Correct 3 ms 712 KB Output is correct
18 Correct 3 ms 712 KB Output is correct
19 Correct 3 ms 712 KB Output is correct
20 Correct 3 ms 712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 8 ms 480 KB Output is correct
3 Correct 7 ms 480 KB Output is correct
4 Correct 8 ms 492 KB Output is correct
5 Correct 8 ms 624 KB Output is correct
6 Correct 6 ms 624 KB Output is correct
7 Correct 7 ms 624 KB Output is correct
8 Correct 6 ms 636 KB Output is correct
9 Correct 7 ms 636 KB Output is correct
10 Correct 7 ms 636 KB Output is correct
11 Correct 6 ms 636 KB Output is correct
12 Correct 7 ms 712 KB Output is correct
13 Correct 6 ms 712 KB Output is correct
14 Correct 7 ms 712 KB Output is correct
15 Correct 7 ms 712 KB Output is correct
16 Correct 4 ms 712 KB Output is correct
17 Correct 3 ms 712 KB Output is correct
18 Correct 3 ms 712 KB Output is correct
19 Correct 3 ms 712 KB Output is correct
20 Correct 3 ms 712 KB Output is correct
21 Correct 21 ms 712 KB Output is correct
22 Correct 18 ms 748 KB Output is correct
23 Correct 22 ms 748 KB Output is correct
24 Correct 19 ms 748 KB Output is correct
25 Correct 19 ms 748 KB Output is correct
26 Correct 18 ms 764 KB Output is correct
27 Correct 19 ms 932 KB Output is correct
28 Correct 18 ms 932 KB Output is correct
29 Correct 19 ms 932 KB Output is correct
30 Correct 7 ms 932 KB Output is correct
31 Correct 7 ms 932 KB Output is correct
32 Correct 7 ms 932 KB Output is correct
33 Correct 6 ms 932 KB Output is correct
34 Correct 7 ms 932 KB Output is correct
35 Correct 8 ms 932 KB Output is correct
36 Correct 8 ms 932 KB Output is correct
37 Correct 8 ms 1052 KB Output is correct
38 Correct 8 ms 1052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1052 KB Output is correct
2 Correct 5 ms 1052 KB Output is correct
3 Correct 6 ms 1052 KB Output is correct
4 Correct 6 ms 1052 KB Output is correct
5 Correct 6 ms 1052 KB Output is correct
6 Correct 10 ms 1052 KB Output is correct
7 Correct 11 ms 1052 KB Output is correct
8 Correct 11 ms 1052 KB Output is correct
9 Correct 11 ms 1100 KB Output is correct
10 Correct 11 ms 1100 KB Output is correct
11 Correct 6 ms 1100 KB Output is correct
12 Correct 5 ms 1100 KB Output is correct
13 Correct 6 ms 1128 KB Output is correct
14 Correct 6 ms 1128 KB Output is correct
15 Correct 6 ms 1128 KB Output is correct
16 Correct 4 ms 1128 KB Output is correct
17 Correct 4 ms 1128 KB Output is correct
18 Correct 4 ms 1128 KB Output is correct
19 Correct 3 ms 1128 KB Output is correct
20 Correct 4 ms 1128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 8 ms 480 KB Output is correct
3 Correct 7 ms 480 KB Output is correct
4 Correct 8 ms 492 KB Output is correct
5 Correct 8 ms 624 KB Output is correct
6 Correct 6 ms 624 KB Output is correct
7 Correct 7 ms 624 KB Output is correct
8 Correct 6 ms 636 KB Output is correct
9 Correct 7 ms 636 KB Output is correct
10 Correct 7 ms 636 KB Output is correct
11 Correct 6 ms 636 KB Output is correct
12 Correct 7 ms 712 KB Output is correct
13 Correct 6 ms 712 KB Output is correct
14 Correct 7 ms 712 KB Output is correct
15 Correct 7 ms 712 KB Output is correct
16 Correct 4 ms 712 KB Output is correct
17 Correct 3 ms 712 KB Output is correct
18 Correct 3 ms 712 KB Output is correct
19 Correct 3 ms 712 KB Output is correct
20 Correct 3 ms 712 KB Output is correct
21 Correct 21 ms 712 KB Output is correct
22 Correct 18 ms 748 KB Output is correct
23 Correct 22 ms 748 KB Output is correct
24 Correct 19 ms 748 KB Output is correct
25 Correct 19 ms 748 KB Output is correct
26 Correct 18 ms 764 KB Output is correct
27 Correct 19 ms 932 KB Output is correct
28 Correct 18 ms 932 KB Output is correct
29 Correct 19 ms 932 KB Output is correct
30 Correct 7 ms 932 KB Output is correct
31 Correct 7 ms 932 KB Output is correct
32 Correct 7 ms 932 KB Output is correct
33 Correct 6 ms 932 KB Output is correct
34 Correct 7 ms 932 KB Output is correct
35 Correct 8 ms 932 KB Output is correct
36 Correct 8 ms 932 KB Output is correct
37 Correct 8 ms 1052 KB Output is correct
38 Correct 8 ms 1052 KB Output is correct
39 Correct 6 ms 1052 KB Output is correct
40 Correct 5 ms 1052 KB Output is correct
41 Correct 6 ms 1052 KB Output is correct
42 Correct 6 ms 1052 KB Output is correct
43 Correct 6 ms 1052 KB Output is correct
44 Correct 10 ms 1052 KB Output is correct
45 Correct 11 ms 1052 KB Output is correct
46 Correct 11 ms 1052 KB Output is correct
47 Correct 11 ms 1100 KB Output is correct
48 Correct 11 ms 1100 KB Output is correct
49 Correct 6 ms 1100 KB Output is correct
50 Correct 5 ms 1100 KB Output is correct
51 Correct 6 ms 1128 KB Output is correct
52 Correct 6 ms 1128 KB Output is correct
53 Correct 6 ms 1128 KB Output is correct
54 Correct 4 ms 1128 KB Output is correct
55 Correct 4 ms 1128 KB Output is correct
56 Correct 4 ms 1128 KB Output is correct
57 Correct 3 ms 1128 KB Output is correct
58 Correct 4 ms 1128 KB Output is correct
59 Correct 460 ms 1128 KB Output is correct
60 Correct 404 ms 1172 KB Output is correct
61 Correct 383 ms 1184 KB Output is correct
62 Correct 463 ms 1196 KB Output is correct
63 Correct 425 ms 1208 KB Output is correct
64 Correct 1053 ms 1220 KB Output is correct
65 Correct 1070 ms 1220 KB Output is correct
66 Correct 1067 ms 1244 KB Output is correct
67 Correct 1065 ms 1256 KB Output is correct
68 Correct 1045 ms 1268 KB Output is correct
69 Correct 399 ms 1280 KB Output is correct
70 Correct 397 ms 1280 KB Output is correct
71 Correct 392 ms 1304 KB Output is correct
72 Correct 433 ms 1440 KB Output is correct
73 Correct 439 ms 1440 KB Output is correct
74 Correct 49 ms 1440 KB Output is correct
75 Correct 44 ms 1440 KB Output is correct
76 Correct 46 ms 1440 KB Output is correct
77 Correct 47 ms 1440 KB Output is correct
78 Correct 48 ms 1440 KB Output is correct