# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
792838 | IvanJ | Boat (APIO16_boat) | C++17 | 12 ms | 16268 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 pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 505;
const int MOD = 1e9 + 7;
int add(int x, int y) {x += y;if(x >= MOD) x -= MOD;return x;}
int sub(int x, int y) {x -= y;if(x < 0) x += MOD;return x;}
int n;
int a[maxn], b[maxn];
int main() {
scanf("%d", &n);
for(int i = 0;i < n;i++)
scanf("%d%d", a + i, b + i);
vector<int> dp(1e6 + 1, 0), pref(1e6 + 1, 0);
int maxi = 0;
for(int i = 0;i < n;i++) {
maxi = max(maxi, b[i]);
for(int j = a[i];j <= b[i];j++) {
if(i == 0) dp[j] = 1;
dp[j] = add(dp[j], pref[j - 1]);
}
if(i == 0) dp[0] = 1;
//for(int j = 0;j <= maxi;j++) cout << dp[j] << " ";
//cout << "\n";
pref[0] = dp[0];
for(int j = 1;j <= maxi;j++)
pref[j] = add(pref[j - 1], dp[j]);
}
printf("%d\n", sub(pref[maxi], (n > 1)));
return 0;
}
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... |