Submission #163032

# Submission time Handle Problem Language Result Execution time Memory
163032 2019-11-11T03:50:58 Z HungAnhGoldIBO2020 Boat (APIO16_boat) C++14
100 / 100
986 ms 508 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=502;
const int mod=1e9+7;
int used[N],sum[N],dp[N],ndp[N],choose[N],rev[N];
vector<pair<int,int> > ope;
int binpow(int x,int y){
	int tich=1;
	while(y){
		if(y&1){
			tich*=x;
			tich%=mod;
		}
		x*=x;
		x%=mod;
		y>>=1;
	}
	return tich;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>j>>k;
		k++;
		ope.push_back({j,i});
		ope.push_back({k,i});
	}
	sort(ope.begin(),ope.end());
	rev[0]=1;
	for(i=1;i<=n;i++){
		rev[i]=binpow(i,mod-2);
	}
	i=0;
	j=0;
	dp[0]=1;
	while(i<ope.size()){
		while(j<ope.size()&&ope[j].first==ope[i].first){
			used[ope[j].second]^=1;
			j++;
		}
		if(j==ope.size()){
			break;
		}
		for(k=1;k<=n;k++){
			sum[k]=sum[k-1]+used[k];
			choose[k]=0;
			//cout<<sum[k]<<' ';
		}
		//cout<<endl;
		int len=ope[j].first-ope[i].first,val=sum[n],c1,c2;
		//cout<<len<<' '<<val<<endl;
		for(k=1;k<=val;k++){
			c1=len;
			c2=1;
			assert(k<=n);
			for(l=0;l<min(k,len+1);l++){
				choose[k]+=c1*c2;
				choose[k]%=mod;
				c1=c1*(len-l-1);
				c1%=mod;
				c1=c1*rev[l+2];
				c1%=mod;
				c2=c2*(k-l-1);
				c2%=mod;
				c2=c2*rev[l+1];
				c2%=mod;
			}
		}
		for(k=0;k<=n;k++){
			ndp[k]=dp[k];
			if(used[k]){
				for(l=0;l<k;l++){
					ndp[k]+=dp[l]*choose[sum[k]-sum[l]];
//					if(k==2){
//						cout<<l<<' '<<dp[l]<<' '<<choose[sum[k]-sum[l]]<<' '<<sum[k]-sum[l]<<endl;
//					}
					ndp[k]%=mod;
				}
			}
		}
		for(k=0;k<=n;k++){
			dp[k]=ndp[k];
		//	cout<<dp[k]<<' ';
		}
		//cout<<"cac"<<endl;
		i=j;
	}
	int ans=0;
	for(i=1;i<=n;i++){
		ans+=dp[i];
		if(ans>=mod){
			ans-=mod;
		}
	}
	cout<<ans;
}
/*
3
1 2
3 4
5 6
3
1 2
4 5
7 8
26
*/

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:40:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(i<ope.size()){
        ~^~~~~~~~~~~
boat.cpp:41:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(j<ope.size()&&ope[j].first==ope[i].first){
         ~^~~~~~~~~~~
boat.cpp:45:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(j==ope.size()){
      ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 4 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 4 ms 376 KB Output is correct
19 Correct 4 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 4 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 4 ms 376 KB Output is correct
19 Correct 4 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 231 ms 448 KB Output is correct
22 Correct 222 ms 508 KB Output is correct
23 Correct 208 ms 376 KB Output is correct
24 Correct 224 ms 352 KB Output is correct
25 Correct 218 ms 376 KB Output is correct
26 Correct 312 ms 452 KB Output is correct
27 Correct 319 ms 376 KB Output is correct
28 Correct 387 ms 504 KB Output is correct
29 Correct 309 ms 376 KB Output is correct
30 Correct 7 ms 376 KB Output is correct
31 Correct 7 ms 376 KB Output is correct
32 Correct 6 ms 376 KB Output is correct
33 Correct 7 ms 376 KB Output is correct
34 Correct 8 ms 376 KB Output is correct
35 Correct 6 ms 376 KB Output is correct
36 Correct 7 ms 376 KB Output is correct
37 Correct 12 ms 424 KB Output is correct
38 Correct 6 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 10 ms 376 KB Output is correct
7 Correct 9 ms 376 KB Output is correct
8 Correct 10 ms 376 KB Output is correct
9 Correct 10 ms 376 KB Output is correct
10 Correct 10 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 7 ms 376 KB Output is correct
16 Correct 4 ms 376 KB Output is correct
17 Correct 4 ms 380 KB Output is correct
18 Correct 4 ms 376 KB Output is correct
19 Correct 4 ms 376 KB Output is correct
20 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 4 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 4 ms 376 KB Output is correct
19 Correct 4 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 231 ms 448 KB Output is correct
22 Correct 222 ms 508 KB Output is correct
23 Correct 208 ms 376 KB Output is correct
24 Correct 224 ms 352 KB Output is correct
25 Correct 218 ms 376 KB Output is correct
26 Correct 312 ms 452 KB Output is correct
27 Correct 319 ms 376 KB Output is correct
28 Correct 387 ms 504 KB Output is correct
29 Correct 309 ms 376 KB Output is correct
30 Correct 7 ms 376 KB Output is correct
31 Correct 7 ms 376 KB Output is correct
32 Correct 6 ms 376 KB Output is correct
33 Correct 7 ms 376 KB Output is correct
34 Correct 8 ms 376 KB Output is correct
35 Correct 6 ms 376 KB Output is correct
36 Correct 7 ms 376 KB Output is correct
37 Correct 12 ms 424 KB Output is correct
38 Correct 6 ms 376 KB Output is correct
39 Correct 6 ms 376 KB Output is correct
40 Correct 5 ms 376 KB Output is correct
41 Correct 6 ms 376 KB Output is correct
42 Correct 6 ms 376 KB Output is correct
43 Correct 6 ms 376 KB Output is correct
44 Correct 10 ms 376 KB Output is correct
45 Correct 9 ms 376 KB Output is correct
46 Correct 10 ms 376 KB Output is correct
47 Correct 10 ms 376 KB Output is correct
48 Correct 10 ms 376 KB Output is correct
49 Correct 6 ms 376 KB Output is correct
50 Correct 5 ms 376 KB Output is correct
51 Correct 6 ms 376 KB Output is correct
52 Correct 5 ms 376 KB Output is correct
53 Correct 7 ms 376 KB Output is correct
54 Correct 4 ms 376 KB Output is correct
55 Correct 4 ms 380 KB Output is correct
56 Correct 4 ms 376 KB Output is correct
57 Correct 4 ms 376 KB Output is correct
58 Correct 4 ms 376 KB Output is correct
59 Correct 499 ms 480 KB Output is correct
60 Correct 453 ms 456 KB Output is correct
61 Correct 430 ms 504 KB Output is correct
62 Correct 505 ms 484 KB Output is correct
63 Correct 477 ms 504 KB Output is correct
64 Correct 940 ms 456 KB Output is correct
65 Correct 941 ms 376 KB Output is correct
66 Correct 945 ms 448 KB Output is correct
67 Correct 986 ms 444 KB Output is correct
68 Correct 936 ms 504 KB Output is correct
69 Correct 393 ms 456 KB Output is correct
70 Correct 397 ms 376 KB Output is correct
71 Correct 392 ms 376 KB Output is correct
72 Correct 408 ms 376 KB Output is correct
73 Correct 422 ms 504 KB Output is correct
74 Correct 72 ms 376 KB Output is correct
75 Correct 68 ms 376 KB Output is correct
76 Correct 73 ms 424 KB Output is correct
77 Correct 73 ms 376 KB Output is correct
78 Correct 74 ms 504 KB Output is correct