답안 #745218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
745218 2023-05-19T15:02:41 Z amirhoseinfar1385 Boat (APIO16_boat) C++17
58 / 100
2000 ms 3376 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<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<int>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]=ww(ps[i]);
			}
		}
	}
	long long res=ps[sz+8];
	res+=mod-1;
	res%=mod;
	cout<<res<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 2260 KB Output is correct
2 Correct 407 ms 2260 KB Output is correct
3 Correct 403 ms 2260 KB Output is correct
4 Correct 402 ms 2380 KB Output is correct
5 Correct 400 ms 2260 KB Output is correct
6 Correct 416 ms 2356 KB Output is correct
7 Correct 411 ms 2356 KB Output is correct
8 Correct 422 ms 2356 KB Output is correct
9 Correct 407 ms 2364 KB Output is correct
10 Correct 400 ms 2368 KB Output is correct
11 Correct 387 ms 2260 KB Output is correct
12 Correct 414 ms 2260 KB Output is correct
13 Correct 413 ms 2260 KB Output is correct
14 Correct 407 ms 2372 KB Output is correct
15 Correct 412 ms 2360 KB Output is correct
16 Correct 76 ms 696 KB Output is correct
17 Correct 84 ms 724 KB Output is correct
18 Correct 83 ms 596 KB Output is correct
19 Correct 84 ms 724 KB Output is correct
20 Correct 82 ms 712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 2260 KB Output is correct
2 Correct 407 ms 2260 KB Output is correct
3 Correct 403 ms 2260 KB Output is correct
4 Correct 402 ms 2380 KB Output is correct
5 Correct 400 ms 2260 KB Output is correct
6 Correct 416 ms 2356 KB Output is correct
7 Correct 411 ms 2356 KB Output is correct
8 Correct 422 ms 2356 KB Output is correct
9 Correct 407 ms 2364 KB Output is correct
10 Correct 400 ms 2368 KB Output is correct
11 Correct 387 ms 2260 KB Output is correct
12 Correct 414 ms 2260 KB Output is correct
13 Correct 413 ms 2260 KB Output is correct
14 Correct 407 ms 2372 KB Output is correct
15 Correct 412 ms 2360 KB Output is correct
16 Correct 76 ms 696 KB Output is correct
17 Correct 84 ms 724 KB Output is correct
18 Correct 83 ms 596 KB Output is correct
19 Correct 84 ms 724 KB Output is correct
20 Correct 82 ms 712 KB Output is correct
21 Correct 1568 ms 2972 KB Output is correct
22 Correct 1540 ms 2992 KB Output is correct
23 Correct 1449 ms 2948 KB Output is correct
24 Correct 1525 ms 2976 KB Output is correct
25 Correct 1528 ms 2924 KB Output is correct
26 Correct 1920 ms 2896 KB Output is correct
27 Correct 1914 ms 2816 KB Output is correct
28 Correct 1947 ms 2836 KB Output is correct
29 Correct 1938 ms 2816 KB Output is correct
30 Correct 600 ms 3276 KB Output is correct
31 Correct 612 ms 3276 KB Output is correct
32 Correct 590 ms 3252 KB Output is correct
33 Correct 584 ms 3264 KB Output is correct
34 Correct 587 ms 3260 KB Output is correct
35 Correct 404 ms 2364 KB Output is correct
36 Correct 410 ms 2348 KB Output is correct
37 Correct 400 ms 2348 KB Output is correct
38 Correct 421 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 460 KB Output is correct
2 Correct 15 ms 408 KB Output is correct
3 Correct 16 ms 464 KB Output is correct
4 Correct 18 ms 460 KB Output is correct
5 Correct 18 ms 340 KB Output is correct
6 Correct 24 ms 340 KB Output is correct
7 Correct 23 ms 340 KB Output is correct
8 Correct 23 ms 340 KB Output is correct
9 Correct 23 ms 340 KB Output is correct
10 Correct 24 ms 456 KB Output is correct
11 Correct 18 ms 340 KB Output is correct
12 Correct 15 ms 340 KB Output is correct
13 Correct 17 ms 464 KB Output is correct
14 Correct 16 ms 340 KB Output is correct
15 Correct 17 ms 456 KB Output is correct
16 Correct 8 ms 340 KB Output is correct
17 Correct 9 ms 388 KB Output is correct
18 Correct 9 ms 340 KB Output is correct
19 Correct 8 ms 340 KB Output is correct
20 Correct 9 ms 396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 2260 KB Output is correct
2 Correct 407 ms 2260 KB Output is correct
3 Correct 403 ms 2260 KB Output is correct
4 Correct 402 ms 2380 KB Output is correct
5 Correct 400 ms 2260 KB Output is correct
6 Correct 416 ms 2356 KB Output is correct
7 Correct 411 ms 2356 KB Output is correct
8 Correct 422 ms 2356 KB Output is correct
9 Correct 407 ms 2364 KB Output is correct
10 Correct 400 ms 2368 KB Output is correct
11 Correct 387 ms 2260 KB Output is correct
12 Correct 414 ms 2260 KB Output is correct
13 Correct 413 ms 2260 KB Output is correct
14 Correct 407 ms 2372 KB Output is correct
15 Correct 412 ms 2360 KB Output is correct
16 Correct 76 ms 696 KB Output is correct
17 Correct 84 ms 724 KB Output is correct
18 Correct 83 ms 596 KB Output is correct
19 Correct 84 ms 724 KB Output is correct
20 Correct 82 ms 712 KB Output is correct
21 Correct 1568 ms 2972 KB Output is correct
22 Correct 1540 ms 2992 KB Output is correct
23 Correct 1449 ms 2948 KB Output is correct
24 Correct 1525 ms 2976 KB Output is correct
25 Correct 1528 ms 2924 KB Output is correct
26 Correct 1920 ms 2896 KB Output is correct
27 Correct 1914 ms 2816 KB Output is correct
28 Correct 1947 ms 2836 KB Output is correct
29 Correct 1938 ms 2816 KB Output is correct
30 Correct 600 ms 3276 KB Output is correct
31 Correct 612 ms 3276 KB Output is correct
32 Correct 590 ms 3252 KB Output is correct
33 Correct 584 ms 3264 KB Output is correct
34 Correct 587 ms 3260 KB Output is correct
35 Correct 404 ms 2364 KB Output is correct
36 Correct 410 ms 2348 KB Output is correct
37 Correct 400 ms 2348 KB Output is correct
38 Correct 421 ms 2260 KB Output is correct
39 Correct 16 ms 460 KB Output is correct
40 Correct 15 ms 408 KB Output is correct
41 Correct 16 ms 464 KB Output is correct
42 Correct 18 ms 460 KB Output is correct
43 Correct 18 ms 340 KB Output is correct
44 Correct 24 ms 340 KB Output is correct
45 Correct 23 ms 340 KB Output is correct
46 Correct 23 ms 340 KB Output is correct
47 Correct 23 ms 340 KB Output is correct
48 Correct 24 ms 456 KB Output is correct
49 Correct 18 ms 340 KB Output is correct
50 Correct 15 ms 340 KB Output is correct
51 Correct 17 ms 464 KB Output is correct
52 Correct 16 ms 340 KB Output is correct
53 Correct 17 ms 456 KB Output is correct
54 Correct 8 ms 340 KB Output is correct
55 Correct 9 ms 388 KB Output is correct
56 Correct 9 ms 340 KB Output is correct
57 Correct 8 ms 340 KB Output is correct
58 Correct 9 ms 396 KB Output is correct
59 Correct 1974 ms 3360 KB Output is correct
60 Correct 1847 ms 3376 KB Output is correct
61 Correct 1820 ms 3376 KB Output is correct
62 Correct 1898 ms 3372 KB Output is correct
63 Correct 1877 ms 3360 KB Output is correct
64 Execution timed out 2068 ms 3284 KB Time limit exceeded
65 Halted 0 ms 0 KB -