답안 #270546

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
270546 2020-08-17T18:01:11 Z test2 Boat (APIO16_boat) C++14
100 / 100
644 ms 10360 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 26 ms 10104 KB Output is correct
2 Correct 24 ms 10104 KB Output is correct
3 Correct 26 ms 10112 KB Output is correct
4 Correct 27 ms 10104 KB Output is correct
5 Correct 27 ms 10360 KB Output is correct
6 Correct 27 ms 10108 KB Output is correct
7 Correct 26 ms 10108 KB Output is correct
8 Correct 28 ms 10104 KB Output is correct
9 Correct 31 ms 10112 KB Output is correct
10 Correct 25 ms 10272 KB Output is correct
11 Correct 27 ms 10112 KB Output is correct
12 Correct 30 ms 10104 KB Output is correct
13 Correct 31 ms 10240 KB Output is correct
14 Correct 30 ms 10108 KB Output is correct
15 Correct 31 ms 10112 KB Output is correct
16 Correct 29 ms 8576 KB Output is correct
17 Correct 25 ms 8568 KB Output is correct
18 Correct 23 ms 8576 KB Output is correct
19 Correct 23 ms 8568 KB Output is correct
20 Correct 29 ms 8568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 10104 KB Output is correct
2 Correct 24 ms 10104 KB Output is correct
3 Correct 26 ms 10112 KB Output is correct
4 Correct 27 ms 10104 KB Output is correct
5 Correct 27 ms 10360 KB Output is correct
6 Correct 27 ms 10108 KB Output is correct
7 Correct 26 ms 10108 KB Output is correct
8 Correct 28 ms 10104 KB Output is correct
9 Correct 31 ms 10112 KB Output is correct
10 Correct 25 ms 10272 KB Output is correct
11 Correct 27 ms 10112 KB Output is correct
12 Correct 30 ms 10104 KB Output is correct
13 Correct 31 ms 10240 KB Output is correct
14 Correct 30 ms 10108 KB Output is correct
15 Correct 31 ms 10112 KB Output is correct
16 Correct 29 ms 8576 KB Output is correct
17 Correct 25 ms 8568 KB Output is correct
18 Correct 23 ms 8576 KB Output is correct
19 Correct 23 ms 8568 KB Output is correct
20 Correct 29 ms 8568 KB Output is correct
21 Correct 331 ms 10152 KB Output is correct
22 Correct 319 ms 9976 KB Output is correct
23 Correct 288 ms 9916 KB Output is correct
24 Correct 314 ms 10116 KB Output is correct
25 Correct 314 ms 10104 KB Output is correct
26 Correct 550 ms 9976 KB Output is correct
27 Correct 568 ms 10104 KB Output is correct
28 Correct 556 ms 10104 KB Output is correct
29 Correct 561 ms 10028 KB Output is correct
30 Correct 27 ms 10232 KB Output is correct
31 Correct 32 ms 10156 KB Output is correct
32 Correct 30 ms 10104 KB Output is correct
33 Correct 27 ms 10112 KB Output is correct
34 Correct 27 ms 10104 KB Output is correct
35 Correct 30 ms 10132 KB Output is correct
36 Correct 29 ms 10112 KB Output is correct
37 Correct 31 ms 10104 KB Output is correct
38 Correct 28 ms 10112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 8576 KB Output is correct
2 Correct 26 ms 8568 KB Output is correct
3 Correct 26 ms 8576 KB Output is correct
4 Correct 26 ms 8568 KB Output is correct
5 Correct 27 ms 8576 KB Output is correct
6 Correct 32 ms 8576 KB Output is correct
7 Correct 27 ms 8568 KB Output is correct
8 Correct 26 ms 8568 KB Output is correct
9 Correct 27 ms 8568 KB Output is correct
10 Correct 26 ms 8576 KB Output is correct
11 Correct 25 ms 8576 KB Output is correct
12 Correct 26 ms 8576 KB Output is correct
13 Correct 25 ms 8568 KB Output is correct
14 Correct 24 ms 8568 KB Output is correct
15 Correct 24 ms 8568 KB Output is correct
16 Correct 25 ms 8448 KB Output is correct
17 Correct 26 ms 8440 KB Output is correct
18 Correct 23 ms 8448 KB Output is correct
19 Correct 23 ms 8440 KB Output is correct
20 Correct 23 ms 8448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 10104 KB Output is correct
2 Correct 24 ms 10104 KB Output is correct
3 Correct 26 ms 10112 KB Output is correct
4 Correct 27 ms 10104 KB Output is correct
5 Correct 27 ms 10360 KB Output is correct
6 Correct 27 ms 10108 KB Output is correct
7 Correct 26 ms 10108 KB Output is correct
8 Correct 28 ms 10104 KB Output is correct
9 Correct 31 ms 10112 KB Output is correct
10 Correct 25 ms 10272 KB Output is correct
11 Correct 27 ms 10112 KB Output is correct
12 Correct 30 ms 10104 KB Output is correct
13 Correct 31 ms 10240 KB Output is correct
14 Correct 30 ms 10108 KB Output is correct
15 Correct 31 ms 10112 KB Output is correct
16 Correct 29 ms 8576 KB Output is correct
17 Correct 25 ms 8568 KB Output is correct
18 Correct 23 ms 8576 KB Output is correct
19 Correct 23 ms 8568 KB Output is correct
20 Correct 29 ms 8568 KB Output is correct
21 Correct 331 ms 10152 KB Output is correct
22 Correct 319 ms 9976 KB Output is correct
23 Correct 288 ms 9916 KB Output is correct
24 Correct 314 ms 10116 KB Output is correct
25 Correct 314 ms 10104 KB Output is correct
26 Correct 550 ms 9976 KB Output is correct
27 Correct 568 ms 10104 KB Output is correct
28 Correct 556 ms 10104 KB Output is correct
29 Correct 561 ms 10028 KB Output is correct
30 Correct 27 ms 10232 KB Output is correct
31 Correct 32 ms 10156 KB Output is correct
32 Correct 30 ms 10104 KB Output is correct
33 Correct 27 ms 10112 KB Output is correct
34 Correct 27 ms 10104 KB Output is correct
35 Correct 30 ms 10132 KB Output is correct
36 Correct 29 ms 10112 KB Output is correct
37 Correct 31 ms 10104 KB Output is correct
38 Correct 28 ms 10112 KB Output is correct
39 Correct 26 ms 8576 KB Output is correct
40 Correct 26 ms 8568 KB Output is correct
41 Correct 26 ms 8576 KB Output is correct
42 Correct 26 ms 8568 KB Output is correct
43 Correct 27 ms 8576 KB Output is correct
44 Correct 32 ms 8576 KB Output is correct
45 Correct 27 ms 8568 KB Output is correct
46 Correct 26 ms 8568 KB Output is correct
47 Correct 27 ms 8568 KB Output is correct
48 Correct 26 ms 8576 KB Output is correct
49 Correct 25 ms 8576 KB Output is correct
50 Correct 26 ms 8576 KB Output is correct
51 Correct 25 ms 8568 KB Output is correct
52 Correct 24 ms 8568 KB Output is correct
53 Correct 24 ms 8568 KB Output is correct
54 Correct 25 ms 8448 KB Output is correct
55 Correct 26 ms 8440 KB Output is correct
56 Correct 23 ms 8448 KB Output is correct
57 Correct 23 ms 8440 KB Output is correct
58 Correct 23 ms 8448 KB Output is correct
59 Correct 351 ms 10200 KB Output is correct
60 Correct 330 ms 10192 KB Output is correct
61 Correct 313 ms 10360 KB Output is correct
62 Correct 350 ms 10232 KB Output is correct
63 Correct 340 ms 10360 KB Output is correct
64 Correct 633 ms 10292 KB Output is correct
65 Correct 633 ms 10272 KB Output is correct
66 Correct 644 ms 10232 KB Output is correct
67 Correct 634 ms 10104 KB Output is correct
68 Correct 637 ms 10104 KB Output is correct
69 Correct 289 ms 10232 KB Output is correct
70 Correct 285 ms 10104 KB Output is correct
71 Correct 286 ms 10220 KB Output is correct
72 Correct 294 ms 10132 KB Output is correct
73 Correct 303 ms 10108 KB Output is correct
74 Correct 85 ms 8568 KB Output is correct
75 Correct 90 ms 8568 KB Output is correct
76 Correct 89 ms 8568 KB Output is correct
77 Correct 92 ms 8568 KB Output is correct
78 Correct 91 ms 8568 KB Output is correct