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>
#define int long long
using namespace std;
const int MOD = 1000000007;
const int K = 100;
int debug = 0;
signed main() {
#ifndef ONLINE_JUDGE
// for getting input from input.txt
//freopen("input.txt", "r", stdin);
// for writing output to output.txt
//freopen("output.txt", "w", stdout);
#endif
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#endif //fast IO
int n; cin >> n;
int dp[n]; //number of journeys ending at the ith city
vector<int> D(n); vector<int> X(n);
for (int i=0; i<n; i++) {
cin >> D[i];
cin >> X[i];
}
int prop[K][K];
for (int i=0; i<n; i++) {
dp[i] = 0;
}
for (int i=0; i<K; i++) {
for (int j=0; j<K; j++) {
prop[i][j] = 0;
}
}
vector<vector<vector<int>>> req_updates(n); //update values are in form {d_i, residue, value}
dp[0] = 1;
for (int i=0; i<n; i++) {
for (int j=1; j<K; j++) {
if (debug) cout << "adding " << i <<" " << j <<" " << i%j <<" " << prop[j][i%j] << endl;
dp[i]+=prop[j][i%j];
dp[i]%=MOD;
}
int d = D[i];
if (d==0) {
for (auto update:req_updates[i]) {
int di,residue,value;
di=update[0]; residue=update[1]; value=update[2];
if (debug) cout << "removed " << i <<" " << di <<" " << residue <<" " << value << " " << update[3] << endl;
prop[di][residue]-=value; prop[di][residue]%=MOD; prop[di][residue]+=MOD; prop[di][residue]%=MOD;
}
continue;
}
int x = X[i];
int end = i+x*d;
end = min(end,((n-1-(i%d))/d)*d+i%d);
//if (debug) cout << i <<" " << d <<" " << x <<" " << end << " " << ((n-1-(i%d))/d)*d+i%d << endl;
int ans = 0;
if (d<K) {
prop[d][i%d]+=dp[i]; prop[d][i%d]%=MOD;
req_updates[end].push_back({d,i%d,dp[i],i});
if (debug) cout << "added update " << i <<" " << end <<" " << d <<" " << i%d <<" " << dp[i] << endl;
if (debug) cout << "sizing " << req_updates[end].size() << endl;
}
else {
for (int j=i+d; j<=end; j+=d) {
dp[j]+=dp[i]; dp[j]%=MOD;
}
}
for (auto update:req_updates[i]) {
int di,residue,value;
di=update[0]; residue=update[1]; value=update[2];
if (debug) cout << "removed " << i <<" " << di <<" " << residue <<" " << value << " " << update[3] << endl;
prop[di][residue]-=value; prop[di][residue]%=MOD; prop[di][residue]+=MOD; prop[di][residue]%=MOD;
}
}
int su = 0;
for (int i=0; i<n; i++) {
su+=dp[i]; su%=MOD;
if (debug) cout << dp[i] <<" ";
}
if (debug) cout << endl;
cout << su << endl;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:59:13: warning: unused variable 'ans' [-Wunused-variable]
59 | int ans = 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... |