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 task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 1e3 + 5;
const ll INF = 1e18 + 5;
const int MOD = 1e9 + 7;
int n, a[MAXN], b[MAXN];
vector<int> num;
void Input()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i] >> b[i];
num.pb(a[i]);
num.pb(b[i] + 1);
}
}
int l[MAXN];
int dp[MAXN][MAXN];
void add(int& a, int b)
{
a += b;
if (a > MOD)
a -= MOD;
}
int comb[MAXN][MAXN];
void Solve()
{
comb[0][0] = 1;
for (int i = 1; i < MAXN; i++)
{
comb[i][0] = comb[i][i] = 1;
for (int j = 1; j < i; j++)
add(comb[i][j], (comb[i - 1][j] + comb[i - 1][j - 1]) % MOD);
}
sort(num.begin(), num.end());
num.erase(unique(num.begin(), num.end()), num.end());
for (int i = 1; i < num.size(); i++)
{
l[i] = num[i] - num[i - 1];
}
for (int i = 1; i <= n; i++)
{
a[i] = upper_bound(num.begin(), num.end(), a[i]) - num.begin();
b[i] = upper_bound(num.begin(), num.end(), b[i]) - num.begin();
}
for (int i = 0; i < num.size(); i++)
dp[0][i] = 1;
for (int i = 1; i <= n; i++)
{
dp[i][0] = 1;
for (int j = a[i]; j <= b[i]; j++)
{
dp[i][j] = (1ll * dp[i - 1][j - 1] * l[j]) % MOD;
int cnt = 1;
for (int k = i - 1; k; k--)
{
if (a[k] <= j && j <= b[k])
{
cnt++;
add(dp[i][j], 1ll * dp[k - 1][j - 1] * comb[cnt + l[j] - 2][cnt] % MOD);
}
}
}
for (int j = 1; j < num.size(); j++)
{
add(dp[i][j], (1ll * dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + MOD) % MOD);
}
}
cout << (dp[n][(int)num.size() - 1] - 1 + MOD) % MOD;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(task".INP","r"))
{
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
Input();
Solve();
}
Compilation message (stderr)
boat.cpp: In function 'void Solve()':
boat.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 1; i < num.size(); i++)
| ~~^~~~~~~~~~~~
boat.cpp:59:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int i = 0; i < num.size(); i++)
| ~~^~~~~~~~~~~~
boat.cpp:77:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for (int j = 1; j < num.size(); j++)
| ~~^~~~~~~~~~~~
boat.cpp: In function 'int main()':
boat.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | freopen(task".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |