Submission #1065166

# Submission time Handle Problem Language Result Execution time Memory
1065166 2024-08-19T02:06:21 Z ttttttttttttth Trains (BOI24_trains) C++17
100 / 100
182 ms 29580 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

const long long N = 1e5 + 5;
const long long inf = 1e9;
const long long mod = 1e9 + 7;
const int Block = 27;

int n, d[N], x[N];
int dp[N], f[N][Block + 5];

signed main() {
    ios_base :: sync_with_stdio (0);
    cin.tie (0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> d[i] >> x[i];
    }
    for (int i = n; i >= 1; i--) {
        dp[i] = 0;
        if (d[i] == 0) {
            dp[i] = 1;
        } 
        else if (d[i] > Block) {
            for (int j = i + d[i]; j <= min(n, i + d[i] * x[i]); j += d[i]) {
                dp[i] = (dp[i] + dp[j]) % mod;
            }
            dp[i] = (dp[i] + 1) % mod;
        } 
        else {
            dp[i] = 1;
            dp[i] = (dp[i] + ((i + d[i] <= n) ? (f[i + d[i]][d[i]]) : 0)) % mod;
            dp[i] = (dp[i] - ((i + d[i] * (x[i] + 1) <= n) ? (f[(i + d[i] * (x[i] + 1))][d[i]]) : 0) + mod * mod) % mod;
        }
        for (int j = 0; j <= Block; j++) {
            f[i][j] = ((i + j <= n ? f[i + j][j] : 0) + dp[i]) % mod;
        }
    }
    cout << dp[1];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2512 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2512 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2392 KB Output is correct
20 Correct 3 ms 4444 KB Output is correct
21 Correct 1 ms 3164 KB Output is correct
22 Correct 3 ms 4952 KB Output is correct
23 Correct 2 ms 3932 KB Output is correct
24 Correct 2 ms 3420 KB Output is correct
25 Correct 4 ms 4640 KB Output is correct
26 Correct 1 ms 3676 KB Output is correct
27 Correct 2 ms 4652 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 3 ms 4956 KB Output is correct
30 Correct 3 ms 4956 KB Output is correct
31 Correct 3 ms 4956 KB Output is correct
32 Correct 3 ms 4956 KB Output is correct
33 Correct 5 ms 5084 KB Output is correct
34 Correct 3 ms 4956 KB Output is correct
35 Correct 3 ms 4956 KB Output is correct
36 Correct 5 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 3932 KB Output is correct
3 Correct 1 ms 3676 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 17 ms 22380 KB Output is correct
6 Correct 25 ms 28648 KB Output is correct
7 Correct 23 ms 28500 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2508 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 26 ms 28884 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 23 ms 28776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 15196 KB Output is correct
2 Correct 11 ms 13016 KB Output is correct
3 Correct 25 ms 29056 KB Output is correct
4 Correct 19 ms 21596 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2460 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 25 ms 29052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2512 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2392 KB Output is correct
20 Correct 3 ms 4444 KB Output is correct
21 Correct 1 ms 3164 KB Output is correct
22 Correct 3 ms 4952 KB Output is correct
23 Correct 2 ms 3932 KB Output is correct
24 Correct 2 ms 3420 KB Output is correct
25 Correct 4 ms 4640 KB Output is correct
26 Correct 1 ms 3676 KB Output is correct
27 Correct 2 ms 4652 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 3 ms 4956 KB Output is correct
30 Correct 3 ms 4956 KB Output is correct
31 Correct 3 ms 4956 KB Output is correct
32 Correct 3 ms 4956 KB Output is correct
33 Correct 5 ms 5084 KB Output is correct
34 Correct 3 ms 4956 KB Output is correct
35 Correct 3 ms 4956 KB Output is correct
36 Correct 5 ms 4956 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 2 ms 3932 KB Output is correct
39 Correct 1 ms 3676 KB Output is correct
40 Correct 2 ms 4700 KB Output is correct
41 Correct 17 ms 22380 KB Output is correct
42 Correct 25 ms 28648 KB Output is correct
43 Correct 23 ms 28500 KB Output is correct
44 Correct 1 ms 2392 KB Output is correct
45 Correct 0 ms 2396 KB Output is correct
46 Correct 1 ms 2508 KB Output is correct
47 Correct 3 ms 4956 KB Output is correct
48 Correct 26 ms 28884 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 3 ms 4956 KB Output is correct
51 Correct 23 ms 28776 KB Output is correct
52 Correct 13 ms 15196 KB Output is correct
53 Correct 11 ms 13016 KB Output is correct
54 Correct 25 ms 29056 KB Output is correct
55 Correct 19 ms 21596 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 0 ms 2460 KB Output is correct
58 Correct 3 ms 4956 KB Output is correct
59 Correct 25 ms 29052 KB Output is correct
60 Correct 158 ms 24624 KB Output is correct
61 Correct 24 ms 28812 KB Output is correct
62 Correct 29 ms 28252 KB Output is correct
63 Correct 22 ms 28496 KB Output is correct
64 Correct 28 ms 29580 KB Output is correct
65 Correct 97 ms 29008 KB Output is correct
66 Correct 23 ms 29020 KB Output is correct
67 Correct 26 ms 29188 KB Output is correct
68 Correct 23 ms 28840 KB Output is correct
69 Correct 68 ms 28500 KB Output is correct
70 Correct 29 ms 28752 KB Output is correct
71 Correct 25 ms 28764 KB Output is correct
72 Correct 182 ms 28580 KB Output is correct