Submission #270476

# Submission time Handle Problem Language Result Execution time Memory
270476 2020-08-17T16:23:06 Z test2 Boat (APIO16_boat) C++14
9 / 100
2000 ms 9344 KB
#include<bits/stdc++.h>

#define I inline void 

using ll = int ; 
using ld = long double ; 

using namespace std ; 

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

// how interesting!

int n; 

ll ans ; 
map<int , int > used ; 
set<pair<int , int> > st ; 
ll sz[N] ;
vector<pair<int , int> > v ; 
ll f[N] ; 

I add(int u , int v){
	if(u <=v){
		used[u] = used[v] = 1; 
		st.insert({u , v}) ; 
	}
}

vector<int> onepiece[N ] ; 
std::vector<int> szs[N];

ll dp[N][505] ; 

ll mul(ll a , ll b){
	return (1ll * a * b) %mod ; 
}

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 ncr(ll x , ll y){
	ll ret = mul(f[x] , faspow(f[y] , mod -2)) ; 
	ret = mul(ret , faspow(f[x - y] , mod-2)) ; 
	return ret ; 
}

ll solve(int i , int j){
	if(dp[i][j]!=-1)
		return dp[i][j] ; 
	if(i == (int) st.size())
		return 1; 
	ll ret = solve(i+1 , j ) ; 

	int pos = 0 ;
	ll add = 0ll ; 

	int k = 0 ; 
	for(auto u : onepiece[i]){
		if(u > j){
			if( k +1 <= sz[i])
			add = (add + ncr(sz[i] , ++ k  )  )  %mod ; 
			else{
				add = (add + ncr( k , sz[i] - 1 ) - 1 + mod ) %mod ; 
				k++ ; 
			}
			
			ll plls = mul( add , solve(i+1,  u) ) ; 
			ret = (ret + plls ) %mod  ; 
		}
		pos ++ ; 
	}
	return dp[i][j] = ret ; 
}

ll conts[N] ; 

int main(){	
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ; 
	memset(dp , -1 , sizeof dp) ; 

	f[0] = 1ll ; 
	for(int i =1 ; i < N ;i++){
		f[i]= mul(f[i-1] , i) ; 
	}

	//freopen("in.in" , "r" , stdin) ;  
	cin >> n; 
	set<int> ev ; 

	for(int i = 0 ;i < n;i++){
		int x , y ; 
		cin >> x >> y ; 
		ev.insert(x) ; 
		ev.insert(y) ; 
		used[x] = used[y] = 1; 
		st.insert({x , x}) ; 
		st.insert({y , y}) ;

		v.push_back({x , y}) ; 
	}
	
	int l = 0 ; 
	for(auto u : ev){
		if(l){
			add(l , u - 1) ; 
		}
		l = u + 1 ; 
	}

	int pos = 0 ; 
	for(auto u : st){ 

		for(int j = 0 ;j < n; j++){
			if(  u.first>= v[j].first &&  u.second <= v[j].second ){
				onepiece[pos].push_back(j + 1) ; 
				szs[pos].push_back( u.second - u.first +1 ) ; 

				sz[pos] += u.second - u.first + 1ll ;
				conts[j] +=  u.second -  u.first + 1 ; 
			}
		}
		sz[pos] = u.second - u.first + 1 ; 
		sort(onepiece[pos].begin() , onepiece[pos].end()) ; 
		pos ++ ; 
	}

	assert(((int) st.size() < 2000)); 

	cout<< (mod + solve(0 ,  0 ) -1 ) %mod ; 
	return 0 ; 
}
# Verdict Execution time Memory Grader output
1 Correct 55 ms 4864 KB Output is correct
2 Correct 56 ms 4736 KB Output is correct
3 Correct 52 ms 4728 KB Output is correct
4 Correct 55 ms 4736 KB Output is correct
5 Correct 55 ms 4728 KB Output is correct
6 Correct 91 ms 4736 KB Output is correct
7 Correct 97 ms 4728 KB Output is correct
8 Correct 94 ms 4736 KB Output is correct
9 Correct 94 ms 4728 KB Output is correct
10 Correct 88 ms 4736 KB Output is correct
11 Correct 90 ms 4712 KB Output is correct
12 Correct 87 ms 4736 KB Output is correct
13 Correct 93 ms 4736 KB Output is correct
14 Correct 93 ms 4728 KB Output is correct
15 Correct 89 ms 4732 KB Output is correct
16 Correct 52 ms 4480 KB Output is correct
17 Correct 47 ms 4480 KB Output is correct
18 Correct 45 ms 4524 KB Output is correct
19 Correct 45 ms 4480 KB Output is correct
20 Correct 48 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 4864 KB Output is correct
2 Correct 56 ms 4736 KB Output is correct
3 Correct 52 ms 4728 KB Output is correct
4 Correct 55 ms 4736 KB Output is correct
5 Correct 55 ms 4728 KB Output is correct
6 Correct 91 ms 4736 KB Output is correct
7 Correct 97 ms 4728 KB Output is correct
8 Correct 94 ms 4736 KB Output is correct
9 Correct 94 ms 4728 KB Output is correct
10 Correct 88 ms 4736 KB Output is correct
11 Correct 90 ms 4712 KB Output is correct
12 Correct 87 ms 4736 KB Output is correct
13 Correct 93 ms 4736 KB Output is correct
14 Correct 93 ms 4728 KB Output is correct
15 Correct 89 ms 4732 KB Output is correct
16 Correct 52 ms 4480 KB Output is correct
17 Correct 47 ms 4480 KB Output is correct
18 Correct 45 ms 4524 KB Output is correct
19 Correct 45 ms 4480 KB Output is correct
20 Correct 48 ms 4600 KB Output is correct
21 Execution timed out 2077 ms 7808 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 9344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 55 ms 4864 KB Output is correct
2 Correct 56 ms 4736 KB Output is correct
3 Correct 52 ms 4728 KB Output is correct
4 Correct 55 ms 4736 KB Output is correct
5 Correct 55 ms 4728 KB Output is correct
6 Correct 91 ms 4736 KB Output is correct
7 Correct 97 ms 4728 KB Output is correct
8 Correct 94 ms 4736 KB Output is correct
9 Correct 94 ms 4728 KB Output is correct
10 Correct 88 ms 4736 KB Output is correct
11 Correct 90 ms 4712 KB Output is correct
12 Correct 87 ms 4736 KB Output is correct
13 Correct 93 ms 4736 KB Output is correct
14 Correct 93 ms 4728 KB Output is correct
15 Correct 89 ms 4732 KB Output is correct
16 Correct 52 ms 4480 KB Output is correct
17 Correct 47 ms 4480 KB Output is correct
18 Correct 45 ms 4524 KB Output is correct
19 Correct 45 ms 4480 KB Output is correct
20 Correct 48 ms 4600 KB Output is correct
21 Execution timed out 2077 ms 7808 KB Time limit exceeded
22 Halted 0 ms 0 KB -