#include <bits/stdc++.h>
using namespace std;
#define int long long
int const N=1e5+5;
int const mod=1e9+7;
int dp[N],suf[N],d[N],x[N];
int n;
void solve12(){
dp[n]=1;
for(int i=n-1;i>=1;i--){
dp[i]=1;
if(d[i]==0)
continue;
for(int j=i+d[i];j<=min(i+(d[i]*x[i]),n);j+=d[i])
dp[i]=(dp[i]+dp[j])%mod;
}
cout<<dp[1]<<endl;
}
void solve3(){
dp[n]=1;
suf[n]=1;
for(int i=n-1;i>=1;i--){
dp[i]=(((1+suf[i+1]-suf[min(n+1,i+x[i]+1)])%mod)+mod)%mod;
suf[i]=(dp[i]+suf[i+1])%mod;
}
cout<<dp[1]<<endl;
}
signed main(){
cin>>n;
bool b=1;
for (int i = 1; i <=n; ++i){
cin>>d[i]>>x[i];
if(d[i]!=1)
b=0;
}
if(n<=10000)
solve12();
else if(b)
solve3();
// else
// solve4();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2420 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2420 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
12 ms |
2612 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
3 ms |
2652 KB |
Output is correct |
23 |
Correct |
60 ms |
2576 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
6 ms |
2396 KB |
Output is correct |
26 |
Correct |
34 ms |
2396 KB |
Output is correct |
27 |
Correct |
121 ms |
2596 KB |
Output is correct |
28 |
Correct |
21 ms |
2396 KB |
Output is correct |
29 |
Correct |
166 ms |
2592 KB |
Output is correct |
30 |
Correct |
4 ms |
2652 KB |
Output is correct |
31 |
Correct |
83 ms |
2616 KB |
Output is correct |
32 |
Correct |
166 ms |
2392 KB |
Output is correct |
33 |
Correct |
4 ms |
2648 KB |
Output is correct |
34 |
Correct |
3 ms |
2648 KB |
Output is correct |
35 |
Correct |
2 ms |
2648 KB |
Output is correct |
36 |
Correct |
10 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
62 ms |
2564 KB |
Output is correct |
3 |
Correct |
34 ms |
2396 KB |
Output is correct |
4 |
Correct |
121 ms |
2600 KB |
Output is correct |
5 |
Correct |
14 ms |
3164 KB |
Output is correct |
6 |
Correct |
34 ms |
3412 KB |
Output is correct |
7 |
Correct |
28 ms |
3440 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
166 ms |
2600 KB |
Output is correct |
12 |
Correct |
29 ms |
3412 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
167 ms |
2396 KB |
Output is correct |
15 |
Correct |
27 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2420 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
12 ms |
2612 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
3 ms |
2652 KB |
Output is correct |
23 |
Correct |
60 ms |
2576 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
6 ms |
2396 KB |
Output is correct |
26 |
Correct |
34 ms |
2396 KB |
Output is correct |
27 |
Correct |
121 ms |
2596 KB |
Output is correct |
28 |
Correct |
21 ms |
2396 KB |
Output is correct |
29 |
Correct |
166 ms |
2592 KB |
Output is correct |
30 |
Correct |
4 ms |
2652 KB |
Output is correct |
31 |
Correct |
83 ms |
2616 KB |
Output is correct |
32 |
Correct |
166 ms |
2392 KB |
Output is correct |
33 |
Correct |
4 ms |
2648 KB |
Output is correct |
34 |
Correct |
3 ms |
2648 KB |
Output is correct |
35 |
Correct |
2 ms |
2648 KB |
Output is correct |
36 |
Correct |
10 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
62 ms |
2564 KB |
Output is correct |
39 |
Correct |
34 ms |
2396 KB |
Output is correct |
40 |
Correct |
121 ms |
2600 KB |
Output is correct |
41 |
Correct |
14 ms |
3164 KB |
Output is correct |
42 |
Correct |
34 ms |
3412 KB |
Output is correct |
43 |
Correct |
28 ms |
3440 KB |
Output is correct |
44 |
Correct |
0 ms |
2396 KB |
Output is correct |
45 |
Correct |
0 ms |
2396 KB |
Output is correct |
46 |
Correct |
0 ms |
2396 KB |
Output is correct |
47 |
Correct |
166 ms |
2600 KB |
Output is correct |
48 |
Correct |
29 ms |
3412 KB |
Output is correct |
49 |
Correct |
1 ms |
2392 KB |
Output is correct |
50 |
Correct |
167 ms |
2396 KB |
Output is correct |
51 |
Correct |
27 ms |
3420 KB |
Output is correct |
52 |
Incorrect |
17 ms |
2652 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |