Submission #1052923

# Submission time Handle Problem Language Result Execution time Memory
1052923 2024-08-11T06:01:30 Z vjudge1 Trains (BOI24_trains) C++17
100 / 100
74 ms 7196 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll N = 1e5 + 10, mod = 1e9 + 7, D = 100;
ll n, dp[N], sm[D][D], a[N][2];
vector<ll> del[N];

void add(ll &x, ll y){
    x += y;
    if (x < 0) x += mod;
    if (x >= mod) x -= mod;
}

int main(){
    cin >> n;
    for (ll i = 1; i <= n; i ++)
        cin >> a[i][0] >> a[i][1];

    dp[1] = 1;
    for (ll i = 1; i <= n; i ++){
        for (ll d = 1; d < D; d ++)
            add(dp[i], sm[d][i % d]);

        for (ll l : del[i]){
            // cout << "At " << i << " deleting " << l << " which is " << -dp[l] << " and contents " << a[l][0] << ", " << l % a[l][0] << endl;
            add(sm[a[l][0]][l % a[l][0]], -dp[l]);
        }

        if (!a[i][0] or !a[i][1]) continue;

        if (a[i][0] >= D){
            for (ll j = i + a[i][0]; j <= n and a[i][1]; j += a[i][0], a[i][1]--)
                add(dp[j], dp[i]);
        }
        else{
            add(sm[a[i][0]][i % a[i][0]], dp[i]);
            ll r = 1ll * i + 1ll * a[i][0] * a[i][1];
            // cout << "Adding " << dp[i] << " on " << a[i][0] << ", " << i % a[i][0] << endl;
            if (r <= n)
                del[r].push_back(i);
        }
    }

    ll ans = 0;
    for (ll i = 1; i <= n; i ++){
        // cout << i << " : " << dp[i] << endl;
        add(ans, dp[i]);
    }

    ans %= mod;
    ans += mod;
    ans %= mod;

    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 0 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 0 ms 4712 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 0 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 0 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4696 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4708 KB Output is correct
19 Correct 1 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 0 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 0 ms 4712 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 0 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 0 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4696 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4708 KB Output is correct
19 Correct 1 ms 4696 KB Output is correct
20 Correct 4 ms 4700 KB Output is correct
21 Correct 3 ms 4700 KB Output is correct
22 Correct 5 ms 4700 KB Output is correct
23 Correct 3 ms 4700 KB Output is correct
24 Correct 2 ms 4700 KB Output is correct
25 Correct 4 ms 4724 KB Output is correct
26 Correct 2 ms 4700 KB Output is correct
27 Correct 4 ms 4700 KB Output is correct
28 Correct 6 ms 4700 KB Output is correct
29 Correct 8 ms 4728 KB Output is correct
30 Correct 6 ms 4728 KB Output is correct
31 Correct 6 ms 4700 KB Output is correct
32 Correct 5 ms 4700 KB Output is correct
33 Correct 7 ms 4724 KB Output is correct
34 Correct 5 ms 4724 KB Output is correct
35 Correct 5 ms 4700 KB Output is correct
36 Correct 5 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 5 ms 4724 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 4 ms 4700 KB Output is correct
5 Correct 29 ms 6480 KB Output is correct
6 Correct 40 ms 4944 KB Output is correct
7 Correct 48 ms 5456 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 5 ms 4700 KB Output is correct
12 Correct 47 ms 4948 KB Output is correct
13 Correct 1 ms 4696 KB Output is correct
14 Correct 6 ms 4700 KB Output is correct
15 Correct 57 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 4724 KB Output is correct
2 Correct 19 ms 4728 KB Output is correct
3 Correct 48 ms 4944 KB Output is correct
4 Correct 39 ms 4948 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 5 ms 4700 KB Output is correct
8 Correct 61 ms 5096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 0 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 0 ms 4712 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 0 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 0 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4696 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4708 KB Output is correct
19 Correct 1 ms 4696 KB Output is correct
20 Correct 4 ms 4700 KB Output is correct
21 Correct 3 ms 4700 KB Output is correct
22 Correct 5 ms 4700 KB Output is correct
23 Correct 3 ms 4700 KB Output is correct
24 Correct 2 ms 4700 KB Output is correct
25 Correct 4 ms 4724 KB Output is correct
26 Correct 2 ms 4700 KB Output is correct
27 Correct 4 ms 4700 KB Output is correct
28 Correct 6 ms 4700 KB Output is correct
29 Correct 8 ms 4728 KB Output is correct
30 Correct 6 ms 4728 KB Output is correct
31 Correct 6 ms 4700 KB Output is correct
32 Correct 5 ms 4700 KB Output is correct
33 Correct 7 ms 4724 KB Output is correct
34 Correct 5 ms 4724 KB Output is correct
35 Correct 5 ms 4700 KB Output is correct
36 Correct 5 ms 4700 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 5 ms 4724 KB Output is correct
39 Correct 2 ms 4700 KB Output is correct
40 Correct 4 ms 4700 KB Output is correct
41 Correct 29 ms 6480 KB Output is correct
42 Correct 40 ms 4944 KB Output is correct
43 Correct 48 ms 5456 KB Output is correct
44 Correct 1 ms 4700 KB Output is correct
45 Correct 1 ms 4700 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 5 ms 4700 KB Output is correct
48 Correct 47 ms 4948 KB Output is correct
49 Correct 1 ms 4696 KB Output is correct
50 Correct 6 ms 4700 KB Output is correct
51 Correct 57 ms 4956 KB Output is correct
52 Correct 23 ms 4724 KB Output is correct
53 Correct 19 ms 4728 KB Output is correct
54 Correct 48 ms 4944 KB Output is correct
55 Correct 39 ms 4948 KB Output is correct
56 Correct 1 ms 4700 KB Output is correct
57 Correct 1 ms 4700 KB Output is correct
58 Correct 5 ms 4700 KB Output is correct
59 Correct 61 ms 5096 KB Output is correct
60 Correct 43 ms 4952 KB Output is correct
61 Correct 47 ms 4968 KB Output is correct
62 Correct 44 ms 7196 KB Output is correct
63 Correct 42 ms 4948 KB Output is correct
64 Correct 69 ms 4976 KB Output is correct
65 Correct 63 ms 4956 KB Output is correct
66 Correct 71 ms 4948 KB Output is correct
67 Correct 53 ms 4944 KB Output is correct
68 Correct 46 ms 4948 KB Output is correct
69 Correct 74 ms 5972 KB Output is correct
70 Correct 45 ms 4980 KB Output is correct
71 Correct 46 ms 5200 KB Output is correct
72 Correct 66 ms 4972 KB Output is correct