# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
549738 | krit3379 | Boat (APIO16_boat) | C++17 | 836 ms | 524288 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;
#define N 505
long long dp[N][N][N],a[N],b[N],l[2*N],r[2*N],ans,mod=1e9+7;
vector<long long> v;
// num -> at i-th scholl -> with up_val
int main(){
int n,i,j,k;
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%lld %lld",&a[i],&b[i]),v.push_back(a[i]),v.push_back(b[i]);
v.push_back(-1);
sort(v.begin(),v.end());
v.resize(unique(v.begin(),v.end())-v.begin());
v.push_back(v.back()+1);
for(i=1;i<=n;i++){
l[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin();
r[i]=lower_bound(v.begin(),v.end(),b[i])-v.begin();
}
for(i=0;i<=n;i++)for(j=0;j<=n;j++)dp[0][i][j]=1;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
for(k=1;k<v.size();k++){
if(l[j]<=k&&k<=r[j])dp[i][j][k]=(dp[i][j][k]+dp[i-1][j-1][k-1]*(v[k+1]-v[k]))%mod;
dp[i][j][k]=(dp[i][j][k]+dp[i][j][k-1]+dp[i][j-1][k]-dp[i][j-1][k-1]+mod)%mod;
}
}
ans=(ans+dp[i][n][v.size()-1])%mod;
}
printf("%lld",ans);
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... |