#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
#define pb push_back
#define B begin()
#define E end()
using namespace std;
int n;
int a[1001000];
int b[1000100];
map<pair<pair<int,int>,int>,int>dp;
map<pair<pair<int,int>,int>,int>go;
const int mod=1e9+7;
//dp[ { {i,last},pl } ]
int f(int i,int last,int pl)
{
if(go[ { {i,last},pl } ]!=0)
return dp[ { {i,last},pl } ]%mod;
if(i==n+1)
return 1;
int g=f(i+1,last,pl);
for(int j=a[i];j<=b[i];j++)
if(j>a[last]+pl)
g+=f(i+1,i,j-a[i]);
//cout<<" "<<i<<" "<<last<<" "<<pl<<endl;
go[ { {i,last},pl } ]=1;
return dp[ { {i,last},pl } ]=g%mod;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//memset(dp,-1,sizeof dp);
cin>>n;
for(int i=1;i<=n;i++){
//a[i]=n-i;
cin>>a[i]>>b[i];
}
cout<<f(1,0,0)-1<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
142 ms |
20044 KB |
Output is correct |
2 |
Correct |
143 ms |
20044 KB |
Output is correct |
3 |
Correct |
144 ms |
19940 KB |
Output is correct |
4 |
Correct |
140 ms |
19916 KB |
Output is correct |
5 |
Correct |
140 ms |
19984 KB |
Output is correct |
6 |
Correct |
152 ms |
19928 KB |
Output is correct |
7 |
Correct |
155 ms |
19988 KB |
Output is correct |
8 |
Correct |
154 ms |
19992 KB |
Output is correct |
9 |
Correct |
160 ms |
19952 KB |
Output is correct |
10 |
Correct |
153 ms |
20016 KB |
Output is correct |
11 |
Correct |
165 ms |
20008 KB |
Output is correct |
12 |
Correct |
153 ms |
20024 KB |
Output is correct |
13 |
Correct |
152 ms |
20012 KB |
Output is correct |
14 |
Correct |
175 ms |
20064 KB |
Output is correct |
15 |
Correct |
150 ms |
20024 KB |
Output is correct |
16 |
Correct |
145 ms |
19976 KB |
Output is correct |
17 |
Correct |
142 ms |
20024 KB |
Output is correct |
18 |
Correct |
153 ms |
20032 KB |
Output is correct |
19 |
Correct |
139 ms |
19932 KB |
Output is correct |
20 |
Correct |
139 ms |
20000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
142 ms |
20044 KB |
Output is correct |
2 |
Correct |
143 ms |
20044 KB |
Output is correct |
3 |
Correct |
144 ms |
19940 KB |
Output is correct |
4 |
Correct |
140 ms |
19916 KB |
Output is correct |
5 |
Correct |
140 ms |
19984 KB |
Output is correct |
6 |
Correct |
152 ms |
19928 KB |
Output is correct |
7 |
Correct |
155 ms |
19988 KB |
Output is correct |
8 |
Correct |
154 ms |
19992 KB |
Output is correct |
9 |
Correct |
160 ms |
19952 KB |
Output is correct |
10 |
Correct |
153 ms |
20016 KB |
Output is correct |
11 |
Correct |
165 ms |
20008 KB |
Output is correct |
12 |
Correct |
153 ms |
20024 KB |
Output is correct |
13 |
Correct |
152 ms |
20012 KB |
Output is correct |
14 |
Correct |
175 ms |
20064 KB |
Output is correct |
15 |
Correct |
150 ms |
20024 KB |
Output is correct |
16 |
Correct |
145 ms |
19976 KB |
Output is correct |
17 |
Correct |
142 ms |
20024 KB |
Output is correct |
18 |
Correct |
153 ms |
20032 KB |
Output is correct |
19 |
Correct |
139 ms |
19932 KB |
Output is correct |
20 |
Correct |
139 ms |
20000 KB |
Output is correct |
21 |
Execution timed out |
2076 ms |
5020 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1845 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
142 ms |
20044 KB |
Output is correct |
2 |
Correct |
143 ms |
20044 KB |
Output is correct |
3 |
Correct |
144 ms |
19940 KB |
Output is correct |
4 |
Correct |
140 ms |
19916 KB |
Output is correct |
5 |
Correct |
140 ms |
19984 KB |
Output is correct |
6 |
Correct |
152 ms |
19928 KB |
Output is correct |
7 |
Correct |
155 ms |
19988 KB |
Output is correct |
8 |
Correct |
154 ms |
19992 KB |
Output is correct |
9 |
Correct |
160 ms |
19952 KB |
Output is correct |
10 |
Correct |
153 ms |
20016 KB |
Output is correct |
11 |
Correct |
165 ms |
20008 KB |
Output is correct |
12 |
Correct |
153 ms |
20024 KB |
Output is correct |
13 |
Correct |
152 ms |
20012 KB |
Output is correct |
14 |
Correct |
175 ms |
20064 KB |
Output is correct |
15 |
Correct |
150 ms |
20024 KB |
Output is correct |
16 |
Correct |
145 ms |
19976 KB |
Output is correct |
17 |
Correct |
142 ms |
20024 KB |
Output is correct |
18 |
Correct |
153 ms |
20032 KB |
Output is correct |
19 |
Correct |
139 ms |
19932 KB |
Output is correct |
20 |
Correct |
139 ms |
20000 KB |
Output is correct |
21 |
Execution timed out |
2076 ms |
5020 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |