Submission #48615

# Submission time Handle Problem Language Result Execution time Memory
48615 2018-05-17T11:33:20 Z nobik Boat (APIO16_boat) C++14
0 / 100
1778 ms 2472 KB
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SIZE(a) ((int)(a).size())
#define ALL(a) (a).begin(), (a).end()

using ll = long long;
using K = long double;

const int inf = 1000*1000*1000 + 7;
const int mod = 1000*1000*1000 + 7;
const int N = 505;

int power(int a, int n) {
	int result = 1;
	while (n > 0) {
		if (n % 2) {
			result = (1LL*result*a) % mod;
		}
		a = (1LL*a*a) % mod;
		n /= 2;
	}
	return result;
}

int inv(int a) {
	return power(a, mod-2);
}

void add(int &x, int y) {
	x += y;
	if (x >= mod) x -= mod;
}

int n, m, l[N], r[N];
vector<int> d;
int f[N][N], g[N][N];

int inside(int id, int piece) {
	return l[id] <= d[piece] && r[id] >= d[piece+1];
}

int iv[N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	cin >> n;
	REP(i, n) {
		cin >> l[i] >> r[i];
		++r[i];
		d.push_back(l[i]);
		d.push_back(r[i]);
	}
	sort(d.begin(), d.end());
	d.erase(unique(d.begin(), d.end()), d.end());
	m = SIZE(d)-1;
	f[0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		iv[i] = inv(i);
	}
	for (int i = 0; i <= n; ++i) REP(j, m) {
		int len = d[j+1]-d[j];
		int first = len;
		int second = 1;
		for (int j = 0; j <= i; ++j) {
			first = 1LL*first*(len-j-1) % mod;
			first = 1LL*first*iv[j+2] % mod;
			add(g[i][j], 1LL*first*second % mod);
			second = 1LL*second*(i-j) % mod;
			second = 1LL*second*iv[j+1] % mod;
		}
	}
	REP(i, n) {
		REP(j, m+1) add(f[i+1][j], f[i][j]);
		REP(j, m) {
			add(f[i][j+1], f[i][j]);
			if (!inside(i, j)) continue;
			add(f[i+1][j+1], 1LL*f[i][j]*(d[j+1]-d[j]) % mod);
			int cnt = -1;
			for (int nxt = i+1; nxt < n; ++nxt) {
				if (!inside(nxt, j)) continue;
				++cnt;
				add(f[nxt+1][j+1], 1LL*f[i][j]*g[cnt][j] % mod);
			}
		}
	}
	int result = mod-1;
	REP(i, m+1) add(result, f[n][i]);
	cout << result << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 1778 ms 2472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1778 ms 2472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 2472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1778 ms 2472 KB Output isn't correct
2 Halted 0 ms 0 KB -