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>
#include<stdint.h>
using namespace std;
#define IOS {cin.tie(0);ios_base::sync_with_stdio(false);}
#define N 505
#define int int64_t
const int MOD = 1000000007;
vector<int> ds;
int a[N],b[N];
int dp[N];
int inv[N];
int powmo(int a,int b,int m){
int r = 1;
for(;b;b>>=1){
if(b&1) r = r*a % m;
a = a*a % m;
}
return r;
}
int32_t main()
{
inv[0] = 1;
for(int i=1;i<N;i++) inv[i] = powmo(i,MOD-2,MOD);
IOS;
int n;
cin >> n;
for(int i=1;i<=n;i++){
cin >> a[i] >> b[i];
ds.push_back(a[i]);
ds.push_back(b[i]+1);
}
sort(ds.begin(),ds.end());
ds.resize(unique(ds.begin(),ds.end()) - ds.begin());
for(int i=1;i<=n;i++){
a[i] = (int)(lower_bound(ds.begin(),ds.end(),a[i]) - ds.begin());
b[i] = (int)(lower_bound(ds.begin(),ds.end(),b[i]+1) - ds.begin());
}
dp[0] = 1;
for(int i=0;i+1<ds.size();i++){
int L = ds[i+1] - ds[i];
for(int j=n;j>0;j--) if(a[j] <= i && i < b[j]){
int f = 0, c = L, m = 1;
for(int k=j-1;k>=0;k--){
(f += c * dp[k]) %= MOD;
if(a[k] <= i && i < b[k]) c = c * inv[m+1] % MOD * (L+m) % MOD,m++;
}
(dp[j] += f) %= MOD;
}
}
int ans = 0;
for(int i=1;i<=n;i++) (ans += dp[i]) %= MOD;
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
boat.cpp: In function 'int32_t main()':
boat.cpp:41:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i+1<ds.size();i++){
~~~^~~~~~~~~~
# | 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... |