#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;
}
void solve4(){
dp[n]=1;
suf[n]=1;
for(int i=n-1;i>=1;i--){
dp[i]=1;
if(d[i]==0){
suf[i]=1;
continue;
}
for(int j=i+d[i];j<=n;j+=d[i]){
if(d[j]==d[i]){
dp[i]=(dp[i]+suf[j])%mod;
break;
}
dp[i]=(dp[i]+dp[j])%mod;
}
suf[i]=((dp[i]*2)%mod + (mod-1))%mod;
}
// for(int i=1;i<=n;i++)
// cout<<dp[i]<<endl;
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
2396 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 |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
2396 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 |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 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 |
11 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
5 ms |
2652 KB |
Output is correct |
23 |
Correct |
60 ms |
2568 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
8 ms |
2564 KB |
Output is correct |
26 |
Correct |
35 ms |
2552 KB |
Output is correct |
27 |
Correct |
142 ms |
2612 KB |
Output is correct |
28 |
Correct |
24 ms |
2392 KB |
Output is correct |
29 |
Correct |
194 ms |
2584 KB |
Output is correct |
30 |
Correct |
4 ms |
2648 KB |
Output is correct |
31 |
Correct |
86 ms |
2596 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 |
2396 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
36 |
Correct |
12 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
62 ms |
2568 KB |
Output is correct |
3 |
Correct |
38 ms |
2396 KB |
Output is correct |
4 |
Correct |
121 ms |
2592 KB |
Output is correct |
5 |
Correct |
16 ms |
3164 KB |
Output is correct |
6 |
Correct |
22 ms |
3416 KB |
Output is correct |
7 |
Correct |
24 ms |
3416 KB |
Output is correct |
8 |
Correct |
1 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 |
169 ms |
2624 KB |
Output is correct |
12 |
Correct |
30 ms |
3440 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
169 ms |
2588 KB |
Output is correct |
15 |
Correct |
29 ms |
3436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
2908 KB |
Output is correct |
2 |
Correct |
13 ms |
2908 KB |
Output is correct |
3 |
Correct |
29 ms |
3432 KB |
Output is correct |
4 |
Correct |
23 ms |
3164 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
171 ms |
2580 KB |
Output is correct |
8 |
Correct |
32 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
2396 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 |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 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 |
11 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
5 ms |
2652 KB |
Output is correct |
23 |
Correct |
60 ms |
2568 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
8 ms |
2564 KB |
Output is correct |
26 |
Correct |
35 ms |
2552 KB |
Output is correct |
27 |
Correct |
142 ms |
2612 KB |
Output is correct |
28 |
Correct |
24 ms |
2392 KB |
Output is correct |
29 |
Correct |
194 ms |
2584 KB |
Output is correct |
30 |
Correct |
4 ms |
2648 KB |
Output is correct |
31 |
Correct |
86 ms |
2596 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 |
2396 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
36 |
Correct |
12 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
62 ms |
2568 KB |
Output is correct |
39 |
Correct |
38 ms |
2396 KB |
Output is correct |
40 |
Correct |
121 ms |
2592 KB |
Output is correct |
41 |
Correct |
16 ms |
3164 KB |
Output is correct |
42 |
Correct |
22 ms |
3416 KB |
Output is correct |
43 |
Correct |
24 ms |
3416 KB |
Output is correct |
44 |
Correct |
1 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 |
169 ms |
2624 KB |
Output is correct |
48 |
Correct |
30 ms |
3440 KB |
Output is correct |
49 |
Correct |
0 ms |
2396 KB |
Output is correct |
50 |
Correct |
169 ms |
2588 KB |
Output is correct |
51 |
Correct |
29 ms |
3436 KB |
Output is correct |
52 |
Correct |
20 ms |
2908 KB |
Output is correct |
53 |
Correct |
13 ms |
2908 KB |
Output is correct |
54 |
Correct |
29 ms |
3432 KB |
Output is correct |
55 |
Correct |
23 ms |
3164 KB |
Output is correct |
56 |
Correct |
0 ms |
2396 KB |
Output is correct |
57 |
Correct |
0 ms |
2396 KB |
Output is correct |
58 |
Correct |
171 ms |
2580 KB |
Output is correct |
59 |
Correct |
32 ms |
3412 KB |
Output is correct |
60 |
Incorrect |
32 ms |
3180 KB |
Output isn't correct |
61 |
Halted |
0 ms |
0 KB |
- |