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>
#pragma GCC optimize("O3")
using namespace std;
const int N = 1e5+10;
const int B = sqrt(N);
int n;
int d[N], x[N], dp[N];
int pref[B][B];
const int mod = 1e9+7;
void calc(int pos){
if(d[pos] == 0) return;
int comp = x[pos];
comp = min(comp, (n-pos)/d[pos]);
//cout << pos << ' ' << comp << ' ';
if(comp <= B){
for(int i = 1;pos+d[pos]*i <= n and i <= comp;i++){
dp[pos] += dp[pos+d[pos]*i];
dp[pos] %= mod;
}
return;
}
else{
dp[pos] += pref[d[pos]][pos % d[pos]];
dp[pos] %= mod;
return;
}
}
void upd(int pos){
for(int i = 1;i < B;i++){
pref[i][pos % i] += dp[pos];
pref[i][pos % i] %= mod;
}
return;
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
for(int i = 1;i <= n;i++){
cin >> d[i] >> x[i];
}
for(int i = 1;i <= n;i++){
dp[i] = 1;
}
for(int i = n;i >= 1;i--){
calc(i);
upd(i);
}
cout << dp[1] << '\n';
return 0;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |