Submission #745220

# Submission time Handle Problem Language Result Execution time Memory
745220 2023-05-19T15:04:21 Z amirhoseinfar1385 Boat (APIO16_boat) C++17
58 / 100
2000 ms 3380 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;
}
 
inline 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<int>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<int>>dp(sz+10,vector<int>(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++){
			int cnt=allind[j]-allind[j-1];
			for(int h=n;h>=2;h--){
				dp[j][h]+=1ll*dp[j][h-1]*(cnt-(h-1))%mod*rev[h]%mod;
				dp[j][h]=ww(dp[j][h]);
			}
			dp[j][1]+=1ll*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 193 ms 2260 KB Output is correct
2 Correct 154 ms 2260 KB Output is correct
3 Correct 153 ms 2260 KB Output is correct
4 Correct 175 ms 2260 KB Output is correct
5 Correct 150 ms 2260 KB Output is correct
6 Correct 170 ms 2368 KB Output is correct
7 Correct 153 ms 2260 KB Output is correct
8 Correct 149 ms 2260 KB Output is correct
9 Correct 162 ms 2364 KB Output is correct
10 Correct 156 ms 2356 KB Output is correct
11 Correct 157 ms 2260 KB Output is correct
12 Correct 172 ms 2360 KB Output is correct
13 Correct 168 ms 2364 KB Output is correct
14 Correct 153 ms 2356 KB Output is correct
15 Correct 149 ms 2372 KB Output is correct
16 Correct 29 ms 596 KB Output is correct
17 Correct 34 ms 724 KB Output is correct
18 Correct 31 ms 724 KB Output is correct
19 Correct 29 ms 724 KB Output is correct
20 Correct 35 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 193 ms 2260 KB Output is correct
2 Correct 154 ms 2260 KB Output is correct
3 Correct 153 ms 2260 KB Output is correct
4 Correct 175 ms 2260 KB Output is correct
5 Correct 150 ms 2260 KB Output is correct
6 Correct 170 ms 2368 KB Output is correct
7 Correct 153 ms 2260 KB Output is correct
8 Correct 149 ms 2260 KB Output is correct
9 Correct 162 ms 2364 KB Output is correct
10 Correct 156 ms 2356 KB Output is correct
11 Correct 157 ms 2260 KB Output is correct
12 Correct 172 ms 2360 KB Output is correct
13 Correct 168 ms 2364 KB Output is correct
14 Correct 153 ms 2356 KB Output is correct
15 Correct 149 ms 2372 KB Output is correct
16 Correct 29 ms 596 KB Output is correct
17 Correct 34 ms 724 KB Output is correct
18 Correct 31 ms 724 KB Output is correct
19 Correct 29 ms 724 KB Output is correct
20 Correct 35 ms 596 KB Output is correct
21 Correct 1248 ms 2980 KB Output is correct
22 Correct 1246 ms 3004 KB Output is correct
23 Correct 1224 ms 2952 KB Output is correct
24 Correct 1262 ms 3024 KB Output is correct
25 Correct 1218 ms 2928 KB Output is correct
26 Correct 1622 ms 2836 KB Output is correct
27 Correct 1611 ms 2820 KB Output is correct
28 Correct 1635 ms 2836 KB Output is correct
29 Correct 1727 ms 2820 KB Output is correct
30 Correct 252 ms 3260 KB Output is correct
31 Correct 281 ms 3264 KB Output is correct
32 Correct 234 ms 3260 KB Output is correct
33 Correct 217 ms 3260 KB Output is correct
34 Correct 221 ms 3264 KB Output is correct
35 Correct 158 ms 2356 KB Output is correct
36 Correct 140 ms 2356 KB Output is correct
37 Correct 152 ms 2260 KB Output is correct
38 Correct 148 ms 2348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 340 KB Output is correct
2 Correct 13 ms 340 KB Output is correct
3 Correct 12 ms 464 KB Output is correct
4 Correct 14 ms 340 KB Output is correct
5 Correct 14 ms 460 KB Output is correct
6 Correct 19 ms 456 KB Output is correct
7 Correct 19 ms 456 KB Output is correct
8 Correct 18 ms 464 KB Output is correct
9 Correct 19 ms 464 KB Output is correct
10 Correct 19 ms 456 KB Output is correct
11 Correct 14 ms 460 KB Output is correct
12 Correct 12 ms 340 KB Output is correct
13 Correct 13 ms 464 KB Output is correct
14 Correct 12 ms 464 KB Output is correct
15 Correct 14 ms 340 KB Output is correct
16 Correct 7 ms 340 KB Output is correct
17 Correct 7 ms 392 KB Output is correct
18 Correct 7 ms 340 KB Output is correct
19 Correct 6 ms 340 KB Output is correct
20 Correct 7 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 193 ms 2260 KB Output is correct
2 Correct 154 ms 2260 KB Output is correct
3 Correct 153 ms 2260 KB Output is correct
4 Correct 175 ms 2260 KB Output is correct
5 Correct 150 ms 2260 KB Output is correct
6 Correct 170 ms 2368 KB Output is correct
7 Correct 153 ms 2260 KB Output is correct
8 Correct 149 ms 2260 KB Output is correct
9 Correct 162 ms 2364 KB Output is correct
10 Correct 156 ms 2356 KB Output is correct
11 Correct 157 ms 2260 KB Output is correct
12 Correct 172 ms 2360 KB Output is correct
13 Correct 168 ms 2364 KB Output is correct
14 Correct 153 ms 2356 KB Output is correct
15 Correct 149 ms 2372 KB Output is correct
16 Correct 29 ms 596 KB Output is correct
17 Correct 34 ms 724 KB Output is correct
18 Correct 31 ms 724 KB Output is correct
19 Correct 29 ms 724 KB Output is correct
20 Correct 35 ms 596 KB Output is correct
21 Correct 1248 ms 2980 KB Output is correct
22 Correct 1246 ms 3004 KB Output is correct
23 Correct 1224 ms 2952 KB Output is correct
24 Correct 1262 ms 3024 KB Output is correct
25 Correct 1218 ms 2928 KB Output is correct
26 Correct 1622 ms 2836 KB Output is correct
27 Correct 1611 ms 2820 KB Output is correct
28 Correct 1635 ms 2836 KB Output is correct
29 Correct 1727 ms 2820 KB Output is correct
30 Correct 252 ms 3260 KB Output is correct
31 Correct 281 ms 3264 KB Output is correct
32 Correct 234 ms 3260 KB Output is correct
33 Correct 217 ms 3260 KB Output is correct
34 Correct 221 ms 3264 KB Output is correct
35 Correct 158 ms 2356 KB Output is correct
36 Correct 140 ms 2356 KB Output is correct
37 Correct 152 ms 2260 KB Output is correct
38 Correct 148 ms 2348 KB Output is correct
39 Correct 12 ms 340 KB Output is correct
40 Correct 13 ms 340 KB Output is correct
41 Correct 12 ms 464 KB Output is correct
42 Correct 14 ms 340 KB Output is correct
43 Correct 14 ms 460 KB Output is correct
44 Correct 19 ms 456 KB Output is correct
45 Correct 19 ms 456 KB Output is correct
46 Correct 18 ms 464 KB Output is correct
47 Correct 19 ms 464 KB Output is correct
48 Correct 19 ms 456 KB Output is correct
49 Correct 14 ms 460 KB Output is correct
50 Correct 12 ms 340 KB Output is correct
51 Correct 13 ms 464 KB Output is correct
52 Correct 12 ms 464 KB Output is correct
53 Correct 14 ms 340 KB Output is correct
54 Correct 7 ms 340 KB Output is correct
55 Correct 7 ms 392 KB Output is correct
56 Correct 7 ms 340 KB Output is correct
57 Correct 6 ms 340 KB Output is correct
58 Correct 7 ms 340 KB Output is correct
59 Correct 1579 ms 3364 KB Output is correct
60 Correct 1640 ms 3368 KB Output is correct
61 Correct 1633 ms 3368 KB Output is correct
62 Correct 1721 ms 3380 KB Output is correct
63 Correct 1688 ms 3376 KB Output is correct
64 Execution timed out 2075 ms 3284 KB Time limit exceeded
65 Halted 0 ms 0 KB -