Submission #745227

# Submission time Handle Problem Language Result Execution time Memory
745227 2023-05-19T15:11:46 Z amirhoseinfar1385 Boat (APIO16_boat) C++17
58 / 100
2000 ms 6236 KB
#include<bits/stdc++.h>
using namespace std;
int mod=1e9+7;
const int maxn=501;
long long dp[maxn*3+10][maxn+2];
long long ps[maxn*3+10];
int rev[maxn+10];
pair<int,int>all[maxn+10];
vector<int>allind;

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 main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<=n+5;i++){
		rev[i]=mypow(i,mod-2);
	}
	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;
	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]=(dp[j][h]+dp[j][h-1]*(cnt-(h-1))%mod*rev[h])%mod;
			}
			dp[j][1]=(dp[j][1]+ps[j-1]*cnt)%mod;
		}
		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 4172 KB Output is correct
2 Correct 201 ms 4300 KB Output is correct
3 Correct 217 ms 4180 KB Output is correct
4 Correct 220 ms 4236 KB Output is correct
5 Correct 230 ms 4176 KB Output is correct
6 Correct 210 ms 4268 KB Output is correct
7 Correct 240 ms 4184 KB Output is correct
8 Correct 200 ms 4368 KB Output is correct
9 Correct 259 ms 4188 KB Output is correct
10 Correct 216 ms 4176 KB Output is correct
11 Correct 200 ms 4164 KB Output is correct
12 Correct 192 ms 4280 KB Output is correct
13 Correct 200 ms 4256 KB Output is correct
14 Correct 221 ms 4256 KB Output is correct
15 Correct 233 ms 4196 KB Output is correct
16 Correct 40 ms 1008 KB Output is correct
17 Correct 47 ms 1064 KB Output is correct
18 Correct 39 ms 980 KB Output is correct
19 Correct 41 ms 980 KB Output is correct
20 Correct 41 ms 1036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 193 ms 4172 KB Output is correct
2 Correct 201 ms 4300 KB Output is correct
3 Correct 217 ms 4180 KB Output is correct
4 Correct 220 ms 4236 KB Output is correct
5 Correct 230 ms 4176 KB Output is correct
6 Correct 210 ms 4268 KB Output is correct
7 Correct 240 ms 4184 KB Output is correct
8 Correct 200 ms 4368 KB Output is correct
9 Correct 259 ms 4188 KB Output is correct
10 Correct 216 ms 4176 KB Output is correct
11 Correct 200 ms 4164 KB Output is correct
12 Correct 192 ms 4280 KB Output is correct
13 Correct 200 ms 4256 KB Output is correct
14 Correct 221 ms 4256 KB Output is correct
15 Correct 233 ms 4196 KB Output is correct
16 Correct 40 ms 1008 KB Output is correct
17 Correct 47 ms 1064 KB Output is correct
18 Correct 39 ms 980 KB Output is correct
19 Correct 41 ms 980 KB Output is correct
20 Correct 41 ms 1036 KB Output is correct
21 Correct 1387 ms 5460 KB Output is correct
22 Correct 1358 ms 5632 KB Output is correct
23 Correct 1251 ms 5512 KB Output is correct
24 Correct 1463 ms 5592 KB Output is correct
25 Correct 1340 ms 5388 KB Output is correct
26 Correct 1848 ms 5192 KB Output is correct
27 Correct 1823 ms 5108 KB Output is correct
28 Correct 1846 ms 5104 KB Output is correct
29 Correct 1749 ms 5068 KB Output is correct
30 Correct 315 ms 6024 KB Output is correct
31 Correct 287 ms 6092 KB Output is correct
32 Correct 301 ms 6024 KB Output is correct
33 Correct 278 ms 6004 KB Output is correct
34 Correct 490 ms 5924 KB Output is correct
35 Correct 229 ms 4252 KB Output is correct
36 Correct 195 ms 4252 KB Output is correct
37 Correct 186 ms 4204 KB Output is correct
38 Correct 196 ms 4260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1492 KB Output is correct
2 Correct 13 ms 1484 KB Output is correct
3 Correct 15 ms 1520 KB Output is correct
4 Correct 15 ms 1472 KB Output is correct
5 Correct 16 ms 1516 KB Output is correct
6 Correct 23 ms 1472 KB Output is correct
7 Correct 21 ms 1492 KB Output is correct
8 Correct 21 ms 1492 KB Output is correct
9 Correct 23 ms 1488 KB Output is correct
10 Correct 21 ms 1488 KB Output is correct
11 Correct 16 ms 1516 KB Output is correct
12 Correct 14 ms 1512 KB Output is correct
13 Correct 16 ms 1516 KB Output is correct
14 Correct 16 ms 1492 KB Output is correct
15 Correct 15 ms 1516 KB Output is correct
16 Correct 8 ms 796 KB Output is correct
17 Correct 7 ms 852 KB Output is correct
18 Correct 7 ms 852 KB Output is correct
19 Correct 7 ms 852 KB Output is correct
20 Correct 7 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 193 ms 4172 KB Output is correct
2 Correct 201 ms 4300 KB Output is correct
3 Correct 217 ms 4180 KB Output is correct
4 Correct 220 ms 4236 KB Output is correct
5 Correct 230 ms 4176 KB Output is correct
6 Correct 210 ms 4268 KB Output is correct
7 Correct 240 ms 4184 KB Output is correct
8 Correct 200 ms 4368 KB Output is correct
9 Correct 259 ms 4188 KB Output is correct
10 Correct 216 ms 4176 KB Output is correct
11 Correct 200 ms 4164 KB Output is correct
12 Correct 192 ms 4280 KB Output is correct
13 Correct 200 ms 4256 KB Output is correct
14 Correct 221 ms 4256 KB Output is correct
15 Correct 233 ms 4196 KB Output is correct
16 Correct 40 ms 1008 KB Output is correct
17 Correct 47 ms 1064 KB Output is correct
18 Correct 39 ms 980 KB Output is correct
19 Correct 41 ms 980 KB Output is correct
20 Correct 41 ms 1036 KB Output is correct
21 Correct 1387 ms 5460 KB Output is correct
22 Correct 1358 ms 5632 KB Output is correct
23 Correct 1251 ms 5512 KB Output is correct
24 Correct 1463 ms 5592 KB Output is correct
25 Correct 1340 ms 5388 KB Output is correct
26 Correct 1848 ms 5192 KB Output is correct
27 Correct 1823 ms 5108 KB Output is correct
28 Correct 1846 ms 5104 KB Output is correct
29 Correct 1749 ms 5068 KB Output is correct
30 Correct 315 ms 6024 KB Output is correct
31 Correct 287 ms 6092 KB Output is correct
32 Correct 301 ms 6024 KB Output is correct
33 Correct 278 ms 6004 KB Output is correct
34 Correct 490 ms 5924 KB Output is correct
35 Correct 229 ms 4252 KB Output is correct
36 Correct 195 ms 4252 KB Output is correct
37 Correct 186 ms 4204 KB Output is correct
38 Correct 196 ms 4260 KB Output is correct
39 Correct 15 ms 1492 KB Output is correct
40 Correct 13 ms 1484 KB Output is correct
41 Correct 15 ms 1520 KB Output is correct
42 Correct 15 ms 1472 KB Output is correct
43 Correct 16 ms 1516 KB Output is correct
44 Correct 23 ms 1472 KB Output is correct
45 Correct 21 ms 1492 KB Output is correct
46 Correct 21 ms 1492 KB Output is correct
47 Correct 23 ms 1488 KB Output is correct
48 Correct 21 ms 1488 KB Output is correct
49 Correct 16 ms 1516 KB Output is correct
50 Correct 14 ms 1512 KB Output is correct
51 Correct 16 ms 1516 KB Output is correct
52 Correct 16 ms 1492 KB Output is correct
53 Correct 15 ms 1516 KB Output is correct
54 Correct 8 ms 796 KB Output is correct
55 Correct 7 ms 852 KB Output is correct
56 Correct 7 ms 852 KB Output is correct
57 Correct 7 ms 852 KB Output is correct
58 Correct 7 ms 852 KB Output is correct
59 Correct 1723 ms 6224 KB Output is correct
60 Correct 1641 ms 6236 KB Output is correct
61 Correct 1608 ms 6220 KB Output is correct
62 Correct 1716 ms 6236 KB Output is correct
63 Correct 1621 ms 6228 KB Output is correct
64 Execution timed out 2078 ms 6124 KB Time limit exceeded
65 Halted 0 ms 0 KB -