# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1066452 | Essa2006 | Trains (BOI24_trains) | C++14 | 85 ms | 5724 KiB |
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>
using namespace std;
#define ll long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
int n;
cin >> n;
vector<int> D(n), X(n);
vector<ll> dp(n, 1);
vector<vector<int>> Sub(n);
int sq = sqrt(1e5);
for (int i = 0; i < n; i++) {
cin >> D[i] >> X[i];
if (D[i] < sq && i + (ll)D[i] * (X[i] + 1) < n && D[i]) {
Sub[i + D[i] * (X[i] + 1)].push_back(i);
}
}
vector<vector<int>> Ways(sq + 1);
for (int i = 1; i <= sq; i++) {
Ways[i].resize(i);
}
for (int i = n - 1; i >= 0; i--) {
if (D[i] >= sq) {
for (int j = 1; j <= X[i] && i + (ll) j * D[i] < n;j++) {
dp[i] += dp[i + j * D[i]];
dp[i] %= mod;
}
}
else if (D[i]){
dp[i] += Ways[D[i]][i % D[i]];
dp[i] %= mod;
}
for (int j = 1; j <= sq; j++) {
Ways[j][i % j] += dp[i];
Ways[j][i % j] %= mod;
}
for (int j = 0; j < Sub[i].size(); j++) {
dp[Sub[i][j]] -= Ways[i][i % D[Sub[i][j]]];
dp[Sub[i][j]] += mod, dp[Sub[i][j]] %= mod;
}
}
cout << dp[0];
}
Compilation message (stderr)
# | 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... |