Submission #545813

# Submission time Handle Problem Language Result Execution time Memory
545813 2022-04-05T13:36:48 Z Sohsoh84 Boat (APIO16_boat) C++17
0 / 100
7 ms 6640 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 500 + 10;
const ll MOD = 1e9 + 7;

void mkey(int& a) {
	if (a >= MOD) a -= MOD;
}

int n, L[MAXN], R[MAXN], C[MAXN][MAXN], PC[MAXN][MAXN], dp[MAXN][MAXN * 2], ps[2 * MAXN][MAXN];
vector<int> vec;

inline int ind(int x) {
	return lower_bound(all(vec), x) - vec.begin();
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	C[0][0] = PC[0][0] = 1;
	for (int i = 1; i < MAXN; i++) {
		C[i][0] = PC[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			mkey(C[i][j] = C[i - 1][j - 1] + C[i - 1][j]);
			mkey(PC[i][j] = PC[i][j - 1] + C[i][j]);
		}
	}

	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> L[i] >> R[i];
		vec.push_back(L[i]);
		vec.push_back(R[i]);
	}

	vec.push_back(-1);
	sort(all(vec));
	vec.resize(unique(all(vec)) - vec.begin());

	for (int j = 1; j < int(vec.size()); j++)
		for (int i = 1; i <= n; i++)
			ps[j][i] = ps[j][i - 1] + (vec[j - 1] < L[i] && R[i] <= vec[j]);


	fill(dp[0], dp[0] + MAXN, 1);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int l = ind(L[i]), r = ind(R[i]);
		for (int j = 1; j < int(vec.size()); j++) {
			int sz = vec[j] - vec[j - 1];
			dp[i][j] = dp[i][j - 1];
			
			if (j >= l && j <= r)
				for (int k = 0; k < i; k++)
					dp[i][j] = (dp[i][j] + 1ll * PC[sz][ps[j][i - 1] - ps[j][k]] * dp[k][j - 1]) % MOD;
		}

		mkey(ans += dp[i][int(vec.size()) - 1]);
	}

	cout << ans << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 6640 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 6640 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5456 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 6640 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -