Submission #447802

# Submission time Handle Problem Language Result Execution time Memory
447802 2021-07-27T14:48:00 Z dutch Boat (APIO16_boat) C++17
0 / 100
1173 ms 2332 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define valid(x, y) (a[x] <= pts[y] && pts[y+1] <= b[x]+1)

const int MOD = 1e9+7, LIM = 501;

int modInverse(int x){
	int r = 1, p = (MOD - 2) * 2;
	for(int y=x; p/=2; y=(y*y) % MOD)
		if(p & 1) r = (r*y) % MOD;
	return r;
}

int n, a[LIM], b[LIM], dp[LIM][LIM*2], F[LIM], invF[LIM], C[LIM];
vector<int> pts;

int nCr(int x, int y){
	return (((F[x] * invF[y]) % MOD) * invF[x-y]) % MOD;
}

signed main(){
	cin.tie(0)->sync_with_stdio(0);

	cin >> n;
	for(int i=0; i<n; ++i){
		cin >> a[i] >> b[i];
		pts.push_back(a[i]);
		pts.push_back(b[i]+1);
	}
	sort(pts.begin(), pts.end());
	pts.resize(unique(pts.begin(), pts.end()) - pts.begin());

	int m = size(pts) - 1, ans = 0;

	F[0] = invF[0] = 1;
	for(int i=1; i<=n; ++i){
		F[i] = (F[i-1] * i) % MOD;
		invF[i] = modInverse(F[i]);
	}
	for(int k=0; k<m; ++k){
		int diff = pts[k+1] - pts[k];
		for(int i=1; i<=n; ++i){
			int p = 1; C[i] = 0;
			for(int j=1; j<=i; ++j){
				(p *= diff - j + 1) %= MOD;
				C[i] += ((p * invF[j]) % MOD) * nCr(i-1, j-1);
				C[i] %= MOD;
			}
		}
		for(int i=0; i<n; ++i){
			if(!valid(i, k)) continue;
			int cnt = 1;
			for(int j=i; --j>=0; ){
				if(k) (dp[i][k] += dp[j][k-1] * C[cnt]) %= MOD;
				cnt += valid(j, k);
			}
			(dp[i][k] += C[cnt]) %= MOD;
			(ans += dp[i][k]) %= MOD;
			(dp[i][k] += dp[i][k-1]) %= MOD;
		}
	}
	cout << (ans % MOD + MOD) % MOD;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1173 ms 2332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1173 ms 2332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1173 ms 2332 KB Output isn't correct
2 Halted 0 ms 0 KB -