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;
typedef unsigned long long ull;
typedef long double ld;
#define int ll
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()
ull binexp(ull base, ull pow, ull M=MOD){
ull res = 1;
while(pow){
if(pow & 1) res *= base;
pow >>= 1, base *= base;
if(M) base %= M, res %= M;
}
return res;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
vi inv(510);
for(int x = 0; x < 510; x++)
inv[x] = binexp(x, MOD-2);
int N; cin >> N;
vii A(N+1); vi B;
for(int x = 1; x <= N; x++){
cin >> A[x].first >> A[x].second;
A[x].second++;
B.push_back(A[x].first); B.push_back(A[x].second);
}
sort(all(B));
vector<vvi> dp(2, vvi(B.size(), vi(N+1)));
int prev = 0, curr = 1;
for(int c = 1; c < B.size(); c++)
dp[prev][c][0] = 1;
for(int x = 1; x <= N; x++){
dp[curr][0][0] = 1;
for(int c = 1; c < B.size(); c++){
// j = 0 case
dp[curr][c][0] = 0;
for(auto val : dp[curr][c-1])
dp[curr][c][0] += val, dp[curr][c][0] %= MOD;
for(int j = 1; j <= min(x, B[c]-B[c-1]); j++){
dp[curr][c][j] = dp[prev][c][j];
if(A[x].first <= B[c-1] and B[c] <= A[x].second){
int val = (B[c]-B[c-1]-j+1)*inv[j]; val %= MOD;
dp[curr][c][j] += (dp[prev][c][j-1]*val)%MOD; dp[curr][c][j] %= MOD;
}
}
}
swap(prev, curr);
}
int ans = 0;
for(auto val : dp[prev][B.size()-1])
ans += val, ans %= MOD;
cout << (ans-1+MOD)%MOD << endl;
return 0;
}
Compilation message (stderr)
boat.cpp: In function 'int main()':
boat.cpp:52:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int c = 1; c < B.size(); c++)
| ~~^~~~~~~~~~
boat.cpp:57:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int c = 1; c < B.size(); c++){
| ~~^~~~~~~~~~
# | 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... |