Submission #1315451

#TimeUsernameProblemLanguageResultExecution timeMemory
1315451juliany2Trains (BOI24_trains)C++20
100 / 100
228 ms126460 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()

const int mod = 1e9 + 7;

const int N = 1e5 + 7, B = 320;
int n;
int p[N][B];
ll dp[N];
vector<int> l[N];
bool used[N];

int main() {
    cin.tie(0)->sync_with_stdio(0);

    cin >> n;

    dp[1] = 1;
    ll ans = 0;

    for (int i = 1; i <= n; i++) {
        int d, x;
        cin >> d >> x;
        
        for (int j = 1; j < B; j++) {
            if (i - j >= 0) {
                (p[i][j] += p[i - j][j]) %= mod;
            }
            (dp[i] += p[i][j]) %= mod;
        }

        if (d >= B && d <= n) {
            for (int c = 1; c <= x && i + c * d <= n; c++) {
                (dp[i + c * d] += dp[i]) %= mod;
            }
        } else if (d > 0 && d < B) {
            int stops = min(x, (n - i) / d);

            if (stops >= 1) {
                (p[i + d][d] += dp[i]) %= mod;
                
                if (i + d * (stops + 1) <= n) {
                    (p[i + d * (stops + 1)][d] += mod - dp[i]) %= mod;
                }
            }
        }

        (ans += dp[i]) %= mod;
    }

    cout << ans << '\n';

    return 0;
}
#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...