Submission #1289320

#TimeUsernameProblemLanguageResultExecution timeMemory
1289320ladnooooTrains (BOI24_trains)C++20
8 / 100
6 ms1672 KiB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define int long long
#define ll long long

const int maxN = 1e5 + 7;

const int k = 350;

int p[k][k];
int d[maxN], x[maxN];

const int MOD = 1e9 + 7;

int n;

int dp[maxN];

void solve() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> d[i] >> x[i];
        dp[i] = 1;
    }

    for(int i = n; i >= 1; i--) {
        if(d[i] > 0) {
            if(d[i] > sqrt(n)) {
                for(int j = i + d[i]; j <= min(n, i + d[i] * x[i]); j += d[i]) {
                    dp[i] += dp[j];
                    dp[i] %= MOD;
                }
            } else {
                if(i + d[i] <= n) {
                    dp[i] += p[i + d[i]][d[i]] - p[min(i + (x[i] + 1) * d[i], n + 1)][d[i]];
                    dp[i] += MOD;
                    dp[i] %= MOD;
                }
            }
        }
        for(int j = 1; j <= sqrt(n); j++) {
            int add = 0;
            if(i + j <= n) add = p[i + j][j];
            p[i][j] = dp[i] + add;
            p[i][j] %= MOD;
        }
    }

    cout << dp[1] << '\n';
}

signed main() {
  //  freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...