Submission #540784

# Submission time Handle Problem Language Result Execution time Memory
540784 2022-03-21T17:28:59 Z amunduzbaev Boat (APIO16_boat) C++17
0 / 100
537 ms 4236 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array

const int mod = 1e9 + 7;

int bp(int a, int b){
	int r=1;
	while(b){
		if(b&1) r = r * 1ll * a % mod;
		a = a * 1ll * a % mod; b >>= 1;
	} return r;
}

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	vector<int> a(2 * n), p(2 * n), og;
	iota(p.begin(), p.end(), 0);
	for(int i=0;i<n;i++){
		cin>>a[i<<1]>>a[i<<1|1];
		a[i<<1|1]++;
	}
	
	sort(p.begin(), p.end(), [&](int i, int j){
		return (a[i] < a[j]);
	});
	int last=0;
	for(int i=0, j=0;i<n+n;last++){
		while(j<n+n && a[p[j]] == a[p[i]]) j++;
		og.push_back(a[p[i]]);
		while(i < j) a[p[i]] = last, i++;
	}
	
	vector<int> f(n + 1), inv(n + 1);
	f[0] = inv[0] = 1;
	for(int i=1;i<=n;i++){
		f[i] = f[i-1] * 1ll * i % mod;
		inv[i] = bp(f[i], mod - 2);
	}
	
	auto C = [&](int n, int k){
		if(n < k) return 0ll;
		return f[n] * 1ll * inv[k] % mod * inv[n - k] % mod;
	};
	
	vector<vector<int>> cnt(n + 1, vector<int>(last));
	for(int c=1;c<=n;c++){
		for(int k=0;k+1<last;k++){
			int x = og[k+1] - og[k], f = 1;
			for(int j=1;j<=c;j++){
				if(j <= x){
					cnt[c][k] = (cnt[c][k] + C(c, j) * 1ll * inv[j - 1]) % mod;
				}
				f = f * 1ll * (x - j) % mod;
			}
		}
	}
	
	int res = 0;
	vector<vector<int>> dp(n, vector<int>(last));
	for(int i=0;i<n;i++){
		int l = a[i<<1], r = a[i<<1|1];
		for(int k=l;k<r;k++){
			assert(k+1 < last);
			int c=1;
			for(int j=i-1;~j;j--){
				dp[i][k] = (dp[i][k] + (k ? dp[j][k-1] : 0) * 1ll * cnt[c][k]) % mod;
			}
			
			dp[i][k] = (dp[i][k] + cnt[c][k]) % mod;
			if(k) dp[i][k] = (dp[i][k] + dp[i][k-1]) % mod;
		}
		res = (res + dp[i][r-1]) % mod;
		//~ for(int k=0;k<last;k++) cout<<dp[i][k]<<" ";
		//~ cout<<"\n";
	}
	
	cout<<res<<"\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 537 ms 4236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 537 ms 4236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 537 ms 4236 KB Output isn't correct
2 Halted 0 ms 0 KB -