Submission #745215

# Submission time Handle Problem Language Result Execution time Memory
745215 2023-05-19T14:59:52 Z amirhoseinfar1385 Boat (APIO16_boat) C++17
58 / 100
2000 ms 6372 KB
#include<bits/stdc++.h>
using namespace std;
int mod=1e9+7;
 
long long mypow(long long m,long long y){
	if(y==0){
		return 1;
	}
	long long p=mypow(m,(y>>1));
	p*=p;
	p%=mod;
	if(y&1){
		p*=m;
		p%=mod;
	}
	return p;
}
 
int ww(int a){
	if(a>=mod){
		a-=mod;
	}
	return a;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	vector<long long>rev(n+6);
	for(int i=0;i<=n+5;i++){
		rev[i]=mypow(i,mod-2);
	}
	vector<pair<int,int>>all(n+1);
	vector<int>allind;
	for(int i=1;i<=n;i++){
		cin>>all[i].first>>all[i].second;
		allind.push_back(all[i].first);
		allind.push_back(all[i].second);
		allind.push_back(all[i].first-1);
	}
	allind.push_back(0);
	sort(allind.begin(),allind.end());
	allind.resize(unique(allind.begin(),allind.end())-allind.begin());
	int sz=(int)allind.size()+1;
	vector<vector<long long>>dp(sz+10,vector<long long>(n+5));
	vector<long long>ps(sz+10);
	dp[0][0]=1;
	for(int i=0;i<sz+10;i++){
		ps[i]=1;
	}
	for(int i=1;i<=n;i++){
		int l=lower_bound(allind.begin(),allind.end(),all[i].first)-allind.begin();
		int r=lower_bound(allind.begin(),allind.end(),all[i].second)-allind.begin();
		for(int j=l;j<=r;j++){
			long long cnt=allind[j]-allind[j-1];
			for(int h=n;h>=2;h--){
				dp[j][h]+=dp[j][h-1]*(cnt-(h-1))%mod*rev[h]%mod;
				dp[j][h]=ww(dp[j][h]);
			}
			dp[j][1]+=ps[j-1]*cnt%mod;
			dp[j][1]=ww(dp[j][1]);
		}
		ps[0]=dp[0][0];
		for(int i=1;i<=sz+9;i++){
			ps[i]=ps[i-1];
			for(int h=0;h<=n;h++){
				ps[i]+=dp[i][h];
			}
			ps[i]%=mod;
		}
	}
	long long res=ps[sz+8];
	res+=mod-1;
	res%=mod;
	cout<<res<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 259 ms 4360 KB Output is correct
2 Correct 221 ms 4360 KB Output is correct
3 Correct 239 ms 4364 KB Output is correct
4 Correct 245 ms 4308 KB Output is correct
5 Correct 283 ms 4428 KB Output is correct
6 Correct 217 ms 4360 KB Output is correct
7 Correct 224 ms 4360 KB Output is correct
8 Correct 223 ms 4308 KB Output is correct
9 Correct 186 ms 4364 KB Output is correct
10 Correct 183 ms 4308 KB Output is correct
11 Correct 190 ms 4364 KB Output is correct
12 Correct 190 ms 4360 KB Output is correct
13 Correct 259 ms 4308 KB Output is correct
14 Correct 216 ms 4420 KB Output is correct
15 Correct 196 ms 4308 KB Output is correct
16 Correct 41 ms 980 KB Output is correct
17 Correct 50 ms 1108 KB Output is correct
18 Correct 51 ms 1108 KB Output is correct
19 Correct 55 ms 1124 KB Output is correct
20 Correct 40 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 259 ms 4360 KB Output is correct
2 Correct 221 ms 4360 KB Output is correct
3 Correct 239 ms 4364 KB Output is correct
4 Correct 245 ms 4308 KB Output is correct
5 Correct 283 ms 4428 KB Output is correct
6 Correct 217 ms 4360 KB Output is correct
7 Correct 224 ms 4360 KB Output is correct
8 Correct 223 ms 4308 KB Output is correct
9 Correct 186 ms 4364 KB Output is correct
10 Correct 183 ms 4308 KB Output is correct
11 Correct 190 ms 4364 KB Output is correct
12 Correct 190 ms 4360 KB Output is correct
13 Correct 259 ms 4308 KB Output is correct
14 Correct 216 ms 4420 KB Output is correct
15 Correct 196 ms 4308 KB Output is correct
16 Correct 41 ms 980 KB Output is correct
17 Correct 50 ms 1108 KB Output is correct
18 Correct 51 ms 1108 KB Output is correct
19 Correct 55 ms 1124 KB Output is correct
20 Correct 40 ms 1108 KB Output is correct
21 Correct 1325 ms 5588 KB Output is correct
22 Correct 1261 ms 5628 KB Output is correct
23 Correct 1337 ms 5536 KB Output is correct
24 Correct 1318 ms 5588 KB Output is correct
25 Correct 1349 ms 5492 KB Output is correct
26 Correct 1773 ms 5312 KB Output is correct
27 Correct 1758 ms 5284 KB Output is correct
28 Correct 1715 ms 5300 KB Output is correct
29 Correct 1651 ms 5296 KB Output is correct
30 Correct 293 ms 6152 KB Output is correct
31 Correct 300 ms 6100 KB Output is correct
32 Correct 280 ms 6148 KB Output is correct
33 Correct 300 ms 6164 KB Output is correct
34 Correct 296 ms 6128 KB Output is correct
35 Correct 213 ms 4308 KB Output is correct
36 Correct 216 ms 4364 KB Output is correct
37 Correct 198 ms 4368 KB Output is correct
38 Correct 199 ms 4360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 468 KB Output is correct
2 Correct 13 ms 592 KB Output is correct
3 Correct 13 ms 468 KB Output is correct
4 Correct 15 ms 588 KB Output is correct
5 Correct 15 ms 468 KB Output is correct
6 Correct 23 ms 468 KB Output is correct
7 Correct 23 ms 468 KB Output is correct
8 Correct 23 ms 588 KB Output is correct
9 Correct 20 ms 468 KB Output is correct
10 Correct 20 ms 468 KB Output is correct
11 Correct 16 ms 468 KB Output is correct
12 Correct 13 ms 588 KB Output is correct
13 Correct 15 ms 468 KB Output is correct
14 Correct 14 ms 468 KB Output is correct
15 Correct 14 ms 468 KB Output is correct
16 Correct 8 ms 340 KB Output is correct
17 Correct 7 ms 340 KB Output is correct
18 Correct 8 ms 340 KB Output is correct
19 Correct 7 ms 340 KB Output is correct
20 Correct 8 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 259 ms 4360 KB Output is correct
2 Correct 221 ms 4360 KB Output is correct
3 Correct 239 ms 4364 KB Output is correct
4 Correct 245 ms 4308 KB Output is correct
5 Correct 283 ms 4428 KB Output is correct
6 Correct 217 ms 4360 KB Output is correct
7 Correct 224 ms 4360 KB Output is correct
8 Correct 223 ms 4308 KB Output is correct
9 Correct 186 ms 4364 KB Output is correct
10 Correct 183 ms 4308 KB Output is correct
11 Correct 190 ms 4364 KB Output is correct
12 Correct 190 ms 4360 KB Output is correct
13 Correct 259 ms 4308 KB Output is correct
14 Correct 216 ms 4420 KB Output is correct
15 Correct 196 ms 4308 KB Output is correct
16 Correct 41 ms 980 KB Output is correct
17 Correct 50 ms 1108 KB Output is correct
18 Correct 51 ms 1108 KB Output is correct
19 Correct 55 ms 1124 KB Output is correct
20 Correct 40 ms 1108 KB Output is correct
21 Correct 1325 ms 5588 KB Output is correct
22 Correct 1261 ms 5628 KB Output is correct
23 Correct 1337 ms 5536 KB Output is correct
24 Correct 1318 ms 5588 KB Output is correct
25 Correct 1349 ms 5492 KB Output is correct
26 Correct 1773 ms 5312 KB Output is correct
27 Correct 1758 ms 5284 KB Output is correct
28 Correct 1715 ms 5300 KB Output is correct
29 Correct 1651 ms 5296 KB Output is correct
30 Correct 293 ms 6152 KB Output is correct
31 Correct 300 ms 6100 KB Output is correct
32 Correct 280 ms 6148 KB Output is correct
33 Correct 300 ms 6164 KB Output is correct
34 Correct 296 ms 6128 KB Output is correct
35 Correct 213 ms 4308 KB Output is correct
36 Correct 216 ms 4364 KB Output is correct
37 Correct 198 ms 4368 KB Output is correct
38 Correct 199 ms 4360 KB Output is correct
39 Correct 14 ms 468 KB Output is correct
40 Correct 13 ms 592 KB Output is correct
41 Correct 13 ms 468 KB Output is correct
42 Correct 15 ms 588 KB Output is correct
43 Correct 15 ms 468 KB Output is correct
44 Correct 23 ms 468 KB Output is correct
45 Correct 23 ms 468 KB Output is correct
46 Correct 23 ms 588 KB Output is correct
47 Correct 20 ms 468 KB Output is correct
48 Correct 20 ms 468 KB Output is correct
49 Correct 16 ms 468 KB Output is correct
50 Correct 13 ms 588 KB Output is correct
51 Correct 15 ms 468 KB Output is correct
52 Correct 14 ms 468 KB Output is correct
53 Correct 14 ms 468 KB Output is correct
54 Correct 8 ms 340 KB Output is correct
55 Correct 7 ms 340 KB Output is correct
56 Correct 8 ms 340 KB Output is correct
57 Correct 7 ms 340 KB Output is correct
58 Correct 8 ms 456 KB Output is correct
59 Correct 1769 ms 6372 KB Output is correct
60 Correct 1684 ms 6368 KB Output is correct
61 Correct 1638 ms 6368 KB Output is correct
62 Correct 1762 ms 6368 KB Output is correct
63 Correct 1727 ms 6368 KB Output is correct
64 Execution timed out 2070 ms 6344 KB Time limit exceeded
65 Halted 0 ms 0 KB -