답안 #1065201

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065201 2024-08-19T03:08:33 Z ttttttttttttth Trains (BOI24_trains) C++17
100 / 100
167 ms 243284 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 = 300;

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];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2512 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 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 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2512 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 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 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 13 ms 22360 KB Output is correct
21 Correct 5 ms 9564 KB Output is correct
22 Correct 16 ms 26412 KB Output is correct
23 Correct 10 ms 17956 KB Output is correct
24 Correct 7 ms 12376 KB Output is correct
25 Correct 16 ms 23900 KB Output is correct
26 Correct 9 ms 13148 KB Output is correct
27 Correct 13 ms 22876 KB Output is correct
28 Correct 18 ms 26456 KB Output is correct
29 Correct 16 ms 26460 KB Output is correct
30 Correct 16 ms 26484 KB Output is correct
31 Correct 18 ms 26460 KB Output is correct
32 Correct 16 ms 26456 KB Output is correct
33 Correct 18 ms 26460 KB Output is correct
34 Correct 16 ms 26460 KB Output is correct
35 Correct 18 ms 26376 KB Output is correct
36 Correct 17 ms 26456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 11 ms 17956 KB Output is correct
3 Correct 9 ms 13148 KB Output is correct
4 Correct 15 ms 22840 KB Output is correct
5 Correct 113 ms 187868 KB Output is correct
6 Correct 148 ms 242216 KB Output is correct
7 Correct 159 ms 242260 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 16 ms 26532 KB Output is correct
12 Correct 152 ms 242776 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 16 ms 26496 KB Output is correct
15 Correct 149 ms 242652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 118352 KB Output is correct
2 Correct 73 ms 98668 KB Output is correct
3 Correct 146 ms 242768 KB Output is correct
4 Correct 105 ms 174932 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 16 ms 26460 KB Output is correct
8 Correct 152 ms 242772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2512 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 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 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 13 ms 22360 KB Output is correct
21 Correct 5 ms 9564 KB Output is correct
22 Correct 16 ms 26412 KB Output is correct
23 Correct 10 ms 17956 KB Output is correct
24 Correct 7 ms 12376 KB Output is correct
25 Correct 16 ms 23900 KB Output is correct
26 Correct 9 ms 13148 KB Output is correct
27 Correct 13 ms 22876 KB Output is correct
28 Correct 18 ms 26456 KB Output is correct
29 Correct 16 ms 26460 KB Output is correct
30 Correct 16 ms 26484 KB Output is correct
31 Correct 18 ms 26460 KB Output is correct
32 Correct 16 ms 26456 KB Output is correct
33 Correct 18 ms 26460 KB Output is correct
34 Correct 16 ms 26460 KB Output is correct
35 Correct 18 ms 26376 KB Output is correct
36 Correct 17 ms 26456 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 11 ms 17956 KB Output is correct
39 Correct 9 ms 13148 KB Output is correct
40 Correct 15 ms 22840 KB Output is correct
41 Correct 113 ms 187868 KB Output is correct
42 Correct 148 ms 242216 KB Output is correct
43 Correct 159 ms 242260 KB Output is correct
44 Correct 0 ms 2396 KB Output is correct
45 Correct 0 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 16 ms 26532 KB Output is correct
48 Correct 152 ms 242776 KB Output is correct
49 Correct 0 ms 2396 KB Output is correct
50 Correct 16 ms 26496 KB Output is correct
51 Correct 149 ms 242652 KB Output is correct
52 Correct 70 ms 118352 KB Output is correct
53 Correct 73 ms 98668 KB Output is correct
54 Correct 146 ms 242768 KB Output is correct
55 Correct 105 ms 174932 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 16 ms 26460 KB Output is correct
59 Correct 152 ms 242772 KB Output is correct
60 Correct 135 ms 203096 KB Output is correct
61 Correct 145 ms 242496 KB Output is correct
62 Correct 163 ms 242004 KB Output is correct
63 Correct 141 ms 242256 KB Output is correct
64 Correct 153 ms 243284 KB Output is correct
65 Correct 167 ms 242744 KB Output is correct
66 Correct 140 ms 242512 KB Output is correct
67 Correct 148 ms 242976 KB Output is correct
68 Correct 148 ms 242516 KB Output is correct
69 Correct 155 ms 242256 KB Output is correct
70 Correct 156 ms 242512 KB Output is correct
71 Correct 153 ms 242456 KB Output is correct
72 Correct 158 ms 242252 KB Output is correct