#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
const ll mod=1e9+7;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n;
cin>>n;
ll a[n+5],b[n+5];
ll ans=0;
vector<ll>dp[n+5];
for(ll i=1;i<=n;i++){
cin>>a[i]>>b[i];
dp[i].resize(b[i]-a[i]+2);
}
dp[0].pb(1);//first is 0,then ai, ... ,bi
for(ll i=1;i<=n;i++){
ll tot=1;
dp[i][0]=1;
ll c[n+5];
for(ll j=1;j<=n;j++){
c[j]=a[j];
}
for(ll j=a[i];j<=b[i];j++){
for(ll k=1;k<i;k++){
while(c[k]<j&&c[k]<=b[k]){
tot+=dp[k][c[k]-a[k]+1];
tot%=mod;
c[k]++;
}
}
dp[i][j-a[i]+1]=tot;
ans+=dp[i][j-a[i]+1];
ans%=mod;
}
}
cout<<ans<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
504 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
504 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
659 ms |
7332 KB |
Output is correct |
22 |
Correct |
635 ms |
7276 KB |
Output is correct |
23 |
Correct |
587 ms |
6876 KB |
Output is correct |
24 |
Correct |
647 ms |
7516 KB |
Output is correct |
25 |
Correct |
676 ms |
7600 KB |
Output is correct |
26 |
Correct |
983 ms |
8020 KB |
Output is correct |
27 |
Correct |
996 ms |
8104 KB |
Output is correct |
28 |
Correct |
979 ms |
8028 KB |
Output is correct |
29 |
Correct |
980 ms |
8160 KB |
Output is correct |
30 |
Correct |
818 ms |
8252 KB |
Output is correct |
31 |
Correct |
836 ms |
8028 KB |
Output is correct |
32 |
Correct |
827 ms |
8276 KB |
Output is correct |
33 |
Correct |
848 ms |
8276 KB |
Output is correct |
34 |
Correct |
845 ms |
8116 KB |
Output is correct |
35 |
Correct |
512 ms |
7772 KB |
Output is correct |
36 |
Correct |
529 ms |
8028 KB |
Output is correct |
37 |
Correct |
538 ms |
8028 KB |
Output is correct |
38 |
Correct |
550 ms |
8020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
165 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
504 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
659 ms |
7332 KB |
Output is correct |
22 |
Correct |
635 ms |
7276 KB |
Output is correct |
23 |
Correct |
587 ms |
6876 KB |
Output is correct |
24 |
Correct |
647 ms |
7516 KB |
Output is correct |
25 |
Correct |
676 ms |
7600 KB |
Output is correct |
26 |
Correct |
983 ms |
8020 KB |
Output is correct |
27 |
Correct |
996 ms |
8104 KB |
Output is correct |
28 |
Correct |
979 ms |
8028 KB |
Output is correct |
29 |
Correct |
980 ms |
8160 KB |
Output is correct |
30 |
Correct |
818 ms |
8252 KB |
Output is correct |
31 |
Correct |
836 ms |
8028 KB |
Output is correct |
32 |
Correct |
827 ms |
8276 KB |
Output is correct |
33 |
Correct |
848 ms |
8276 KB |
Output is correct |
34 |
Correct |
845 ms |
8116 KB |
Output is correct |
35 |
Correct |
512 ms |
7772 KB |
Output is correct |
36 |
Correct |
529 ms |
8028 KB |
Output is correct |
37 |
Correct |
538 ms |
8028 KB |
Output is correct |
38 |
Correct |
550 ms |
8020 KB |
Output is correct |
39 |
Runtime error |
165 ms |
524288 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |