Submission #1168141

#TimeUsernameProblemLanguageResultExecution timeMemory
1168141stdfloatBoat (APIO16_boat)C++20
0 / 100
261 ms589824 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int md = (int)1e9 + 7;

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);

	int n;
	cin >> n;

	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++)
		cin >> a[i] >> b[i];

	vector<vector<int>> dp(n);
	for (int i = 0; i < n; i++)
		dp[i].assign(b[i] - a[i] + 2, !i);

	for (int i = 1; i < n; i++) {
		for (auto j : dp[i - 1])
			dp[i][0] = (dp[i][0] + j) % md;
		
		for (int j = a[i]; j <= b[i]; j++) {
			dp[i][j - a[i] + 1] = dp[i - 1][0];
			for (int k = a[i - 1]; k <= min(j - 1, b[i - 1]); k++)
				dp[i][j - a[i] + 1] = (dp[i][j - a[i] + 1] + dp[i - 1][k - a[i - 1] + 1]) % md;
		}
	}

	int ans = -1;
	for (auto i : dp[n - 1])
		ans = (ans + i) % md;

	cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...