Submission #480637

#TimeUsernameProblemLanguageResultExecution timeMemory
480637KarliverBoat (APIO16_boat)C++17
31 / 100
1040 ms524292 KiB
    
#include <bits/stdc++.h>

#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(20) << (x)
#define all(v) (v).begin(), (v).end()
using namespace  std;
#define forn(i,n) for (int i = 0; i < (n); ++i)
#define rforn(i, n) for(int i = (n) - 1;i >= 0;--i)
#define sz(x) (int)x.size()

using ll = long long;
int mod = (ll)1e9 + 7;
#define PI acos(-1)
typedef pair<int, int> pairs;

const int INF = 1e9 + 1;
const int N = 2e5 + 100;
const double eps = 1e-7;

template <class T> using V = vector<T>;  
template <class T> using VV = V<V<T>>;  
template<class T, size_t SZ> using AR = array<T, SZ>;
template<class T> using PR = pair<T, T>;
template <typename XPAX>
bool ckma(XPAX &x, XPAX y) {
    return (x < y ? x = y, 1 : 0);
}
template <typename XPAX>
bool ckmi(XPAX &x, XPAX y) {
    return (x > y ? x = y, 1 : 0);
}
int A[N], B[N];

void add(ll &x, ll y) {
    x += y;
    if(x >= mod)x -= mod;
}
void solve() {


    int n;
    cin >> n;

    forn(i, n) cin >> A[i] >> B[i];

    VV<ll> dp(n);
    forn(i, n) dp[i].push_back(0);
    

    

    for(int i = 0;i < n;++i) {
        for(int x = A[i];x <= B[i];++x) {
            ll now = 1;
            for(int j = 0;j < i;++j) {
                if(A[j] < x)
                    add(now, dp[j][min(B[j] - A[j] + 1, x - A[j])]);
            }
            dp[i].push_back((dp[i].back() + now) % mod);
        }
    }

    ll ret = 0;

    forn(i, n) add(ret, dp[i].back());

    cout << ret << '\n';


}
void test_case() {
    int t;
    cin >> t;
    forn(p, t) {

        //cout << "Case #" << p + 1 << ": ";
        solve();
    }
}
int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...