답안 #270583

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
270583 2020-08-17T18:50:59 Z test2 Boat (APIO16_boat) C++14
100 / 100
654 ms 10352 KB
#include<bits/stdc++.h>

#define I inline void 

using ll = long long ; 
using ld = long double ; 

using namespace std ; 

const int N = 1e6 + 7 , mod = 1e9+7 ;  

// how interesting!

int n , m; 
vector<int> lst ; 
int L[N] , R[N] , S[N] ; 
int dp[1001][501] ;

ll faspow(ll x , ll y){
	if(!y)return 1ll ; 
	ll ret = faspow(x , y/2) ; 
	ret = 1ll * ret *ret %mod ;
	if(y&1)ret = 1ll * ret * x %mod ;
	return ret ; 
}

ll inv[N] ; 

int main(){	
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ; 
	//freopen("in.in" , "r" , stdin) ;  
	inv[1] = 1ll ; 
	for(int i = 2; i < N; i++) inv[i] = (mod/i) * (mod-inv[mod%i]) % mod;

		cin >> n ; 
	for(int i = 1 ;i <= n;i++){
		cin >> L[i] >> R[i] ; 
		R[i] ++ ;
		lst.push_back(L[i]) ; 
		lst.push_back(R[i]) ;
	}
	sort(lst.begin() , lst.end()) ; 
	lst.resize(unique(lst.begin() , lst.end()) - lst.begin()) ; 


	for(int i = 1 ;i <= n ;i++){
		L[i] = lower_bound(lst.begin() , lst.end() , L[i]) - lst.begin() + 1; 
		R[i] = lower_bound(lst.begin() , lst.end() , R[i]) - lst.begin() + 1;
	}

	int w = lst.size() ; 
	for(int i = 1 ;i < w ;i++){
		S[i] = lst[i] - lst[i-1] ; 
	}

	dp[0][0] = 1ll ;
	for(int i = 1 ;i < w ;i++){
		dp[i][0] = 1ll ; 

		for(int j = 1 ;j <=n ;j++){
			int count = 1; 
			ll mul = S[i] ; 

			dp[i][j] = dp[i-1][j] ; 

			if(i < L[j] || i >= R[j])
				continue ; 

			for(int k = j -1 ; k >= 0 ; k --){
				dp[i][j] = (dp[i][j] + (mul * dp[i-1][k]) %mod  ) %mod ; 
				if(L[k] <= i && R[k] > i){

					mul = 1ll * mul * (S[i] + count) %mod ; 
					mul = 1ll * mul * inv[count +1] %mod ; 

					count ++ ;
				}	
			}
		}
	}


	ll ans = 0ll ; 
	for(int i = 1 ; i<=n ;i++){
		ans = (ans + dp[w-1][i]) %mod ; 
	}
	cout<< ans ; 
	return 0 ; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 10104 KB Output is correct
2 Correct 25 ms 10112 KB Output is correct
3 Correct 30 ms 10128 KB Output is correct
4 Correct 29 ms 10112 KB Output is correct
5 Correct 31 ms 10104 KB Output is correct
6 Correct 25 ms 10112 KB Output is correct
7 Correct 25 ms 10104 KB Output is correct
8 Correct 30 ms 10112 KB Output is correct
9 Correct 27 ms 10104 KB Output is correct
10 Correct 29 ms 10112 KB Output is correct
11 Correct 28 ms 10112 KB Output is correct
12 Correct 29 ms 10104 KB Output is correct
13 Correct 26 ms 10108 KB Output is correct
14 Correct 30 ms 10104 KB Output is correct
15 Correct 34 ms 10104 KB Output is correct
16 Correct 25 ms 8576 KB Output is correct
17 Correct 25 ms 8568 KB Output is correct
18 Correct 25 ms 8576 KB Output is correct
19 Correct 26 ms 8568 KB Output is correct
20 Correct 29 ms 8568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 10104 KB Output is correct
2 Correct 25 ms 10112 KB Output is correct
3 Correct 30 ms 10128 KB Output is correct
4 Correct 29 ms 10112 KB Output is correct
5 Correct 31 ms 10104 KB Output is correct
6 Correct 25 ms 10112 KB Output is correct
7 Correct 25 ms 10104 KB Output is correct
8 Correct 30 ms 10112 KB Output is correct
9 Correct 27 ms 10104 KB Output is correct
10 Correct 29 ms 10112 KB Output is correct
11 Correct 28 ms 10112 KB Output is correct
12 Correct 29 ms 10104 KB Output is correct
13 Correct 26 ms 10108 KB Output is correct
14 Correct 30 ms 10104 KB Output is correct
15 Correct 34 ms 10104 KB Output is correct
16 Correct 25 ms 8576 KB Output is correct
17 Correct 25 ms 8568 KB Output is correct
18 Correct 25 ms 8576 KB Output is correct
19 Correct 26 ms 8568 KB Output is correct
20 Correct 29 ms 8568 KB Output is correct
21 Correct 332 ms 9920 KB Output is correct
22 Correct 323 ms 9976 KB Output is correct
23 Correct 308 ms 9976 KB Output is correct
24 Correct 348 ms 9972 KB Output is correct
25 Correct 341 ms 9884 KB Output is correct
26 Correct 581 ms 9960 KB Output is correct
27 Correct 589 ms 10104 KB Output is correct
28 Correct 552 ms 9848 KB Output is correct
29 Correct 552 ms 10052 KB Output is correct
30 Correct 26 ms 10104 KB Output is correct
31 Correct 28 ms 10104 KB Output is correct
32 Correct 29 ms 10232 KB Output is correct
33 Correct 27 ms 10104 KB Output is correct
34 Correct 28 ms 10112 KB Output is correct
35 Correct 27 ms 10112 KB Output is correct
36 Correct 26 ms 10104 KB Output is correct
37 Correct 26 ms 10112 KB Output is correct
38 Correct 30 ms 10112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 8568 KB Output is correct
2 Correct 24 ms 8576 KB Output is correct
3 Correct 24 ms 8576 KB Output is correct
4 Correct 25 ms 8576 KB Output is correct
5 Correct 25 ms 8576 KB Output is correct
6 Correct 28 ms 8576 KB Output is correct
7 Correct 26 ms 8576 KB Output is correct
8 Correct 28 ms 8576 KB Output is correct
9 Correct 27 ms 8568 KB Output is correct
10 Correct 27 ms 8568 KB Output is correct
11 Correct 24 ms 8576 KB Output is correct
12 Correct 26 ms 8576 KB Output is correct
13 Correct 24 ms 8576 KB Output is correct
14 Correct 24 ms 8576 KB Output is correct
15 Correct 25 ms 8576 KB Output is correct
16 Correct 23 ms 8448 KB Output is correct
17 Correct 25 ms 8440 KB Output is correct
18 Correct 25 ms 8448 KB Output is correct
19 Correct 24 ms 8448 KB Output is correct
20 Correct 28 ms 8440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 10104 KB Output is correct
2 Correct 25 ms 10112 KB Output is correct
3 Correct 30 ms 10128 KB Output is correct
4 Correct 29 ms 10112 KB Output is correct
5 Correct 31 ms 10104 KB Output is correct
6 Correct 25 ms 10112 KB Output is correct
7 Correct 25 ms 10104 KB Output is correct
8 Correct 30 ms 10112 KB Output is correct
9 Correct 27 ms 10104 KB Output is correct
10 Correct 29 ms 10112 KB Output is correct
11 Correct 28 ms 10112 KB Output is correct
12 Correct 29 ms 10104 KB Output is correct
13 Correct 26 ms 10108 KB Output is correct
14 Correct 30 ms 10104 KB Output is correct
15 Correct 34 ms 10104 KB Output is correct
16 Correct 25 ms 8576 KB Output is correct
17 Correct 25 ms 8568 KB Output is correct
18 Correct 25 ms 8576 KB Output is correct
19 Correct 26 ms 8568 KB Output is correct
20 Correct 29 ms 8568 KB Output is correct
21 Correct 332 ms 9920 KB Output is correct
22 Correct 323 ms 9976 KB Output is correct
23 Correct 308 ms 9976 KB Output is correct
24 Correct 348 ms 9972 KB Output is correct
25 Correct 341 ms 9884 KB Output is correct
26 Correct 581 ms 9960 KB Output is correct
27 Correct 589 ms 10104 KB Output is correct
28 Correct 552 ms 9848 KB Output is correct
29 Correct 552 ms 10052 KB Output is correct
30 Correct 26 ms 10104 KB Output is correct
31 Correct 28 ms 10104 KB Output is correct
32 Correct 29 ms 10232 KB Output is correct
33 Correct 27 ms 10104 KB Output is correct
34 Correct 28 ms 10112 KB Output is correct
35 Correct 27 ms 10112 KB Output is correct
36 Correct 26 ms 10104 KB Output is correct
37 Correct 26 ms 10112 KB Output is correct
38 Correct 30 ms 10112 KB Output is correct
39 Correct 24 ms 8568 KB Output is correct
40 Correct 24 ms 8576 KB Output is correct
41 Correct 24 ms 8576 KB Output is correct
42 Correct 25 ms 8576 KB Output is correct
43 Correct 25 ms 8576 KB Output is correct
44 Correct 28 ms 8576 KB Output is correct
45 Correct 26 ms 8576 KB Output is correct
46 Correct 28 ms 8576 KB Output is correct
47 Correct 27 ms 8568 KB Output is correct
48 Correct 27 ms 8568 KB Output is correct
49 Correct 24 ms 8576 KB Output is correct
50 Correct 26 ms 8576 KB Output is correct
51 Correct 24 ms 8576 KB Output is correct
52 Correct 24 ms 8576 KB Output is correct
53 Correct 25 ms 8576 KB Output is correct
54 Correct 23 ms 8448 KB Output is correct
55 Correct 25 ms 8440 KB Output is correct
56 Correct 25 ms 8448 KB Output is correct
57 Correct 24 ms 8448 KB Output is correct
58 Correct 28 ms 8440 KB Output is correct
59 Correct 348 ms 10104 KB Output is correct
60 Correct 338 ms 10104 KB Output is correct
61 Correct 319 ms 10304 KB Output is correct
62 Correct 357 ms 10232 KB Output is correct
63 Correct 342 ms 10232 KB Output is correct
64 Correct 632 ms 10104 KB Output is correct
65 Correct 630 ms 10268 KB Output is correct
66 Correct 653 ms 10352 KB Output is correct
67 Correct 654 ms 10232 KB Output is correct
68 Correct 634 ms 10104 KB Output is correct
69 Correct 295 ms 10104 KB Output is correct
70 Correct 286 ms 10108 KB Output is correct
71 Correct 286 ms 10208 KB Output is correct
72 Correct 296 ms 10104 KB Output is correct
73 Correct 302 ms 10232 KB Output is correct
74 Correct 90 ms 8568 KB Output is correct
75 Correct 84 ms 8572 KB Output is correct
76 Correct 94 ms 8696 KB Output is correct
77 Correct 87 ms 8568 KB Output is correct
78 Correct 90 ms 8696 KB Output is correct