Submission #408849

# Submission time Handle Problem Language Result Execution time Memory
408849 2021-05-19T18:01:28 Z LouayFarah Boat (APIO16_boat) C++14
0 / 100
248 ms 524292 KB
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
typedef string str;
typedef double db;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"


#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)

const ll MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const ll MX = 1e9 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up

#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define debug(x) cerr << #x << " : " << x << endl;
#define debugs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define debugv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;

void IO() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

vector<pair<int, int>> v;

ll solve(vector<vector<ll>> &dp, ll n, ll m)
{
    if(n==0)
    {
        return dp[n][m] = 1%MOD;
    }
    if(m==0)
        return dp[n][m] = 1%MOD;
    if(m<0)
        return dp[n][m] = 0;

    if(dp[n][m]!=-1)
        return dp[n][m];

    ll res = 0;
    FOR(i, v[n].fi, v[n].se+1)
    {
        if(i<=m)
            res += (solve(dp, n-1, m-1)%MOD);
        res+= (solve(dp, n-1, m)%MOD);
    }
    return dp[n][m] = res%MOD;
}

int main()
{
    boost;
    IO();

    ll n;
    cin >> n;

    ll a, b;
    FOR(i, 0, n)
    {
        cin >> a >> b;
        v.pb(mp(a, b));
    }

    ll m = v[n-1].se;
    ll res = 0;
    FOR(j, v[n-1].fi, v[n-1].se+1)
    {

        vector<vector<ll>> dp(n, vector<ll>(m+1, -1));
        solve(dp, n-1, j);
        res = (res + dp[n-1][j])%MOD;
    }


    cout << res%MOD << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 248 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 248 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 235 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 248 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -