# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1226980 | cpdreamer | Boat (APIO16_boat) | C++20 | 2096 ms | 589824 KiB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
const long long INF = 1e17;
typedef long long ll;
const ll MOD = 1e9+7;
#define F first
#define pb push_back
#define S second
#define P pair
#define V vector
#define all(v) v.begin(), v.end()
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;
void file() {
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
ll add(ll a,ll b) {
return ((a%MOD)+(b%MOD))%MOD;
}
void solve() {
int n;
cin>>n;
ll A[n];
ll B[n];
V<ll>dp[n];
for (int i=0;i<n;i++) {
cin>>A[i]>>B[i];
}
for (ll i=0;i<B[0]-A[0]+1;i++) {
dp[0].pb(i+1);
}
for (ll i=1;i<n;i++) {
for (ll j=0;j<B[i]-A[i]+1;j++) {
ll x=1;
for (ll g=i-1;g>=0;g--) {
if (j+A[i]<=A[g]) {
continue;
}
x=add(x,dp[g][min(B[g]-A[g],j+A[i]-1-A[g])]);
}
dp[i].pb(x);
}
for (ll j=1;j<B[i]-A[i]+1;j++) {
dp[i][j]=add(dp[i][j],dp[i][j-1]);
}
}
ll ans=0;
for (ll i=0;i<n;i++) {
ans=add(ans,dp[i][B[i]-A[i]]);
}
cout<<ans<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
//file();
solve();
}
Compilation message (stderr)
# | 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... |