이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
typedef long long ll;
ll sumLast(vector<ll>& suf, int x){
if(x >= (int)suf.size()) return suf.back();
if(!x) return 0;
return (suf.back() + MOD - suf[(int)suf.size() - x - 1]) % MOD;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int N; cin >> N;
vector<int> x(N), d(N);
for(int i = 0; i < N; i++){
cin >> d[i] >> x[i];
}
int sqr = sqrt(N);
vector<vector<vector<ll>>> suffix(sqr);
//It's efficiente because each index will be in sqrt vectors.
for(int i = 1; i < sqr; i++){
suffix[i].assign(i, {0});
}
vector<ll> dp(N, 0);
for(int i = N - 1; i >= 0; i--){
dp[i]++; //Just ending there.
if(d[i] >= sqr){
int curr = i + d[i];
int currMult = 1;
while(curr < N && currMult <= x[i]){
dp[i] += dp[curr]; dp[i] %= MOD;
currMult++;
curr += d[i];
}
}else if(d[i] > 0){
int md = i % d[i];
//I want the sum of the last x ones.
dp[i] += sumLast(suffix[d[i]][md], x[i]);
dp[i] %= MOD;
}
for(int div = 1; div < sqr; div++){
int md = i % div;
suffix[div][md].push_back((suffix[div][md].back() + dp[i]) % MOD);
}
}
cout << dp[0] << "\n";
}
# | 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... |