# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
52370 | pzdba | Boat (APIO16_boat) | C++14 | 8 ms | 2296 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 int mod = 1e9+7;
int a[505], b[505];
map<int, int> ht;
map<int, int>::iterator its;
int rev[1005];
int dp[505][1005];
int main(){
int n;
scanf("%d", &n);
for(int i=1;i<=n;i++){
scanf("%d%d", &a[i], &b[i]);
ht[a[i]] = 1;
ht[b[i]] = 1;
}
int hv = 1;
for(its = ht.begin();its != ht.end();its++) its->second = hv++, rev[hv-1] = its->first;
for(int i=1;i<=n;i++) a[i] = ht[a[i]], b[i] = ht[b[i]];
for(int i=1;i<=n;i++){
if(i == 1){
dp[i][0] = 1;
for(int j=a[i];j<=b[i];j++){
if(j == a[i]) dp[i][j] = 1;
else dp[i][j] = (rev[j] - rev[j-1])%mod;
}
}
else{
dp[i][0] = dp[i-1][0]+1;
for(int j=a[i];j<=b[i];j++){
int c = 0;
if(j == 1) c = 1;
else c = rev[j]-rev[j-1];
dp[i][j] = (dp[i][j] + 1)%mod;
for(int k=0;k<=j-1;k++){
dp[i][j] = (dp[i][j] + (LL)dp[i-1][k]*c)%mod;
}
}
}
}
int ans = 0;
for(int i=1;i<=2*n;i++){
ans = (ans + dp[n][i])%mod;
}
printf("%d\n", 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... |