Submission #270544

# Submission time Handle Problem Language Result Execution time Memory
270544 2020-08-17T17:58:09 Z test2 Boat (APIO16_boat) C++14
36 / 100
2000 ms 2304 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(ll x){
	return faspow(x , mod - 2) ; 
}

int main(){	
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ; 
	//freopen("in.in" , "r" , stdin) ;  

	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 ; 
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2304 KB Output is correct
2 Correct 3 ms 2304 KB Output is correct
3 Correct 4 ms 2304 KB Output is correct
4 Correct 3 ms 2304 KB Output is correct
5 Correct 3 ms 2304 KB Output is correct
6 Correct 3 ms 2304 KB Output is correct
7 Correct 3 ms 2304 KB Output is correct
8 Correct 3 ms 2304 KB Output is correct
9 Correct 3 ms 2304 KB Output is correct
10 Correct 3 ms 2304 KB Output is correct
11 Correct 3 ms 2304 KB Output is correct
12 Correct 4 ms 2304 KB Output is correct
13 Correct 3 ms 2304 KB Output is correct
14 Correct 3 ms 2304 KB Output is correct
15 Correct 3 ms 2304 KB Output is correct
16 Correct 2 ms 768 KB Output is correct
17 Correct 2 ms 768 KB Output is correct
18 Correct 2 ms 768 KB Output is correct
19 Correct 2 ms 768 KB Output is correct
20 Correct 2 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2304 KB Output is correct
2 Correct 3 ms 2304 KB Output is correct
3 Correct 4 ms 2304 KB Output is correct
4 Correct 3 ms 2304 KB Output is correct
5 Correct 3 ms 2304 KB Output is correct
6 Correct 3 ms 2304 KB Output is correct
7 Correct 3 ms 2304 KB Output is correct
8 Correct 3 ms 2304 KB Output is correct
9 Correct 3 ms 2304 KB Output is correct
10 Correct 3 ms 2304 KB Output is correct
11 Correct 3 ms 2304 KB Output is correct
12 Correct 4 ms 2304 KB Output is correct
13 Correct 3 ms 2304 KB Output is correct
14 Correct 3 ms 2304 KB Output is correct
15 Correct 3 ms 2304 KB Output is correct
16 Correct 2 ms 768 KB Output is correct
17 Correct 2 ms 768 KB Output is correct
18 Correct 2 ms 768 KB Output is correct
19 Correct 2 ms 768 KB Output is correct
20 Correct 2 ms 768 KB Output is correct
21 Execution timed out 2075 ms 1400 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 760 KB Output is correct
2 Correct 27 ms 768 KB Output is correct
3 Correct 38 ms 764 KB Output is correct
4 Correct 42 ms 760 KB Output is correct
5 Correct 47 ms 760 KB Output is correct
6 Correct 96 ms 760 KB Output is correct
7 Correct 94 ms 768 KB Output is correct
8 Correct 99 ms 760 KB Output is correct
9 Correct 92 ms 760 KB Output is correct
10 Correct 93 ms 760 KB Output is correct
11 Correct 43 ms 760 KB Output is correct
12 Correct 29 ms 792 KB Output is correct
13 Correct 37 ms 760 KB Output is correct
14 Correct 36 ms 760 KB Output is correct
15 Correct 43 ms 760 KB Output is correct
16 Correct 27 ms 632 KB Output is correct
17 Correct 21 ms 640 KB Output is correct
18 Correct 24 ms 640 KB Output is correct
19 Correct 21 ms 640 KB Output is correct
20 Correct 27 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2304 KB Output is correct
2 Correct 3 ms 2304 KB Output is correct
3 Correct 4 ms 2304 KB Output is correct
4 Correct 3 ms 2304 KB Output is correct
5 Correct 3 ms 2304 KB Output is correct
6 Correct 3 ms 2304 KB Output is correct
7 Correct 3 ms 2304 KB Output is correct
8 Correct 3 ms 2304 KB Output is correct
9 Correct 3 ms 2304 KB Output is correct
10 Correct 3 ms 2304 KB Output is correct
11 Correct 3 ms 2304 KB Output is correct
12 Correct 4 ms 2304 KB Output is correct
13 Correct 3 ms 2304 KB Output is correct
14 Correct 3 ms 2304 KB Output is correct
15 Correct 3 ms 2304 KB Output is correct
16 Correct 2 ms 768 KB Output is correct
17 Correct 2 ms 768 KB Output is correct
18 Correct 2 ms 768 KB Output is correct
19 Correct 2 ms 768 KB Output is correct
20 Correct 2 ms 768 KB Output is correct
21 Execution timed out 2075 ms 1400 KB Time limit exceeded
22 Halted 0 ms 0 KB -