# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
107864 | Just_Solve_The_Problem | Boat (APIO16_boat) | C++11 | 3 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = (int)507;
const int mod = (int)1e9 + 7;
int add(int a, int b) {
return (a + b) % mod;
}
int mul(int a, int b) {
return (a * 1LL * b) % mod;
}
int n;
vector<int> L, R;
int dp[N];
int pref[2][N];
main() {
scanf("%d", &n);
L.resize(n);
R.resize(n);
for (int i = 0; i < n; i++) {
scanf("%d %d", &L[i], &R[i]);
}
memset(pref, 0, sizeof(pref));
memset(dp, 0, sizeof(dp));
ll ans = 0;
for (int j = 1; j < N; j++) {
if (L[0] <= j && j <= R[0]) {
pref[0][j] = 1;
}
pref[0][j] += pref[0][j - 1];
}
for (int i = 1; i < n; i++) {
for (int j = 1; j < N; j++) {
if (L[i] <= j && j <= R[i]) {
pref[i & 1][j] += pref[(i & 1) ^ 1][j - 1];
if (pref[i & 1][j] >= mod) pref[i & 1][j] -= mod;
dp[j] = pref[i & 1][j];
}
pref[i & 1][j] += pref[i & 1][j - 1];
pref[(i & 1) ^ 1][j - 1] = 0;
}
pref[(i & 1) ^ 1][N - 1] = 0;
}
for (int i = L[n - 1]; i <= R[n - 1]; i++) {
ans += dp[i];
if (ans >= mod) ans -= mod;
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |