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;
int n;
vector<int> a,b;
map<pair<int,int>,int> m;
int dp(int i,int val)
{
//cout<<val<<endl;
if(i==n) return (int)(val!=-1);
if(m.find({i,val})!=m.end()) return m[{i,val}];
int r = dp(i+1,val);
for(int j=max(val,a[i]);j<=b[i];j++) r+=dp(i+1,j+1);
return m[{i,val}] = r;
}
int main()
{
cin>>n;
a.resize(n);
b.resize(n);
for(int i=0;i<n;i++)
{
cin>>a[i]>>b[i];
}
cout<<dp(0,-1)<<endl;
}
# | 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... |