# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
24987 | gabrielsimoes | Boat (APIO16_boat) | C++14 | 0 ms | 17652 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>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int MAXN = 500;
const int MAX = 1e6+10;
int n;
ll a[MAXN], b[MAXN];
ll dp[MAX], sum[MAX];
int main()
{
bool test1 = 1, test2 = 1;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lld %lld", &a[i], &b[i]);
if (a[i] >= MAX || b[i] >= MAX) test2 = 0;
if (a[i] != b[i]) test1 = 0;
}
if (test1) {
dp[0] = 1;
for (int i = 1; i < n; i++) {
dp[i] = dp[i-1] + 1;
for (int k = i-1; k >= 0; k--)
if (a[k] < a[i])
dp[i] = (dp[i] + dp[k]) % MOD;
}
printf("%lld\n", dp[n-1] % MOD);
} else if (test2) {
for (int i = 0; i < MAX; i++) sum[i] = 1;
for (int i = 0; i < n; i++) {
for (int k = b[i]; k >= a[i]; k--)
dp[k] = (dp[k] + sum[k-1]) % MOD;
for (int i = 1; i < MAX; i++)
sum[i] = (sum[i-1] + dp[i]) % MOD;
}
printf("%lld\n", (sum[MAX-1] - 1 + MOD) % MOD);
}
}
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... |