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 ll MOD = 1e9+7, MAXN = 505;
ll n, a[MAXN], b[MAXN];
vector<ll> dis;
ll disz;
ll dp[MAXN][2*MAXN] = {0}, qdp[MAXN][2*MAXN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (ll i = 1; i <= n; i++) cin >> a[i] >> b[i];
for (ll i = 1; i <= n; i++) dis.push_back(a[i]), dis.push_back(b[i]);
dis.push_back(0);
sort(dis.begin(), dis.end());
dis.resize(unique(dis.begin(), dis.end()) - dis.begin());
disz = dis.size();
for (ll i = 1; i <= n; i++) {
ll beg = lower_bound(dis.begin(), dis.end(), a[i]) - dis.begin();
ll lst = lower_bound(dis.begin(), dis.end(), b[i]) - dis.begin();
for (ll j = beg; j < lst; j++) {
ll df = dis[j+1] - dis[j];
dp[i][j] = df; // start sequence here
for (ll k = 1; k < i; k++) {
dp[i][j] += df*qdp[k][j-1];
dp[i][j] %= MOD;
}
}
{
// choose b[i]
dp[i][lst] = 1;
for (ll k = 1; k < i; k++) {
dp[i][lst] += qdp[k][lst-1];
dp[i][lst] %= MOD;
}
}
qdp[i][0] = 0;
for (ll j = 1; j < disz; j++) qdp[i][j] = (qdp[i][j-1] + dp[i][j])%MOD;
}
ll ans = 0;
for (ll i = 1; i <= n; i++) for (ll j = 0; j < disz; j++) {
ans += dp[i][j];
ans %= MOD;
}
cout << ans;
/*cout << "\n";
for (ll i = 1; i <= n; i++) {
for (ll j = 0; j < disz; j++) cout << dp[i][j] << " ";
cout << "\n";
}*/
return 0;
}
# | 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... |