Submission #1057171

# Submission time Handle Problem Language Result Execution time Memory
1057171 2024-08-13T14:42:15 Z 0npata Trains (BOI24_trains) C++17
100 / 100
452 ms 791088 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define vec vector

const int MOD = 1e9 + 7;
const int SQN = 1000;


int32_t main() {
	int N;
	cin >> N;
	vec<int> D(N), X(N);

	for(int i = 0; i<N; i++) {
		cin >> D[i];
		cin >> X[i];
	}


	vec<int> f(N, 1);
	vec<vec<int>> fsum(N, vec<int>(SQN, 1));

	for(int i = N-2; i>=0; i--) {
		if(D[i] == 0) {}
		else if(D[i] >= SQN) {
			for(int j = 1; j<=X[i] && i+(j*D[i]) < N; j++) {
				f[i] += f[i+(j*D[i])];

				f[i] %= MOD;
				assert(i+(j*D[i]) < N);
			}
		}
		else {
			f[i] += ((i+D[i]) < N ? fsum[i+D[i]][D[i]] : 0ll) + MOD - (i+(X[i]+1)*D[i] < N ? fsum[i+(X[i]+1)*D[i]][D[i]] : 0ll);
			f[i] %= MOD;
		}

		for(int j = 1; j<SQN; j++) {
			fsum[i][j] = f[i] + ((i+j) < N ? fsum[i+j][j] : 0);
		}

	}

	cout << f[0] << '\n';

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 37 ms 65840 KB Output is correct
21 Correct 14 ms 23640 KB Output is correct
22 Correct 43 ms 79216 KB Output is correct
23 Correct 26 ms 51288 KB Output is correct
24 Correct 18 ms 32604 KB Output is correct
25 Correct 39 ms 70980 KB Output is correct
26 Correct 19 ms 35676 KB Output is correct
27 Correct 36 ms 67836 KB Output is correct
28 Correct 45 ms 79196 KB Output is correct
29 Correct 44 ms 79340 KB Output is correct
30 Correct 45 ms 79196 KB Output is correct
31 Correct 44 ms 79184 KB Output is correct
32 Correct 46 ms 79340 KB Output is correct
33 Correct 44 ms 79188 KB Output is correct
34 Correct 43 ms 79196 KB Output is correct
35 Correct 43 ms 79196 KB Output is correct
36 Correct 42 ms 79340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 27 ms 51524 KB Output is correct
3 Correct 19 ms 35672 KB Output is correct
4 Correct 37 ms 67676 KB Output is correct
5 Correct 348 ms 610128 KB Output is correct
6 Correct 428 ms 789476 KB Output is correct
7 Correct 420 ms 790352 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 42 ms 79360 KB Output is correct
12 Correct 430 ms 790612 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 44 ms 79460 KB Output is correct
15 Correct 429 ms 790856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 203 ms 380244 KB Output is correct
2 Correct 171 ms 315988 KB Output is correct
3 Correct 432 ms 789424 KB Output is correct
4 Correct 320 ms 566352 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 45 ms 79288 KB Output is correct
8 Correct 441 ms 790864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 37 ms 65840 KB Output is correct
21 Correct 14 ms 23640 KB Output is correct
22 Correct 43 ms 79216 KB Output is correct
23 Correct 26 ms 51288 KB Output is correct
24 Correct 18 ms 32604 KB Output is correct
25 Correct 39 ms 70980 KB Output is correct
26 Correct 19 ms 35676 KB Output is correct
27 Correct 36 ms 67836 KB Output is correct
28 Correct 45 ms 79196 KB Output is correct
29 Correct 44 ms 79340 KB Output is correct
30 Correct 45 ms 79196 KB Output is correct
31 Correct 44 ms 79184 KB Output is correct
32 Correct 46 ms 79340 KB Output is correct
33 Correct 44 ms 79188 KB Output is correct
34 Correct 43 ms 79196 KB Output is correct
35 Correct 43 ms 79196 KB Output is correct
36 Correct 42 ms 79340 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 27 ms 51524 KB Output is correct
39 Correct 19 ms 35672 KB Output is correct
40 Correct 37 ms 67676 KB Output is correct
41 Correct 348 ms 610128 KB Output is correct
42 Correct 428 ms 789476 KB Output is correct
43 Correct 420 ms 790352 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 42 ms 79360 KB Output is correct
48 Correct 430 ms 790612 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 44 ms 79460 KB Output is correct
51 Correct 429 ms 790856 KB Output is correct
52 Correct 203 ms 380244 KB Output is correct
53 Correct 171 ms 315988 KB Output is correct
54 Correct 432 ms 789424 KB Output is correct
55 Correct 320 ms 566352 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 45 ms 79288 KB Output is correct
59 Correct 441 ms 790864 KB Output is correct
60 Correct 370 ms 658512 KB Output is correct
61 Correct 437 ms 790276 KB Output is correct
62 Correct 450 ms 789844 KB Output is correct
63 Correct 415 ms 790340 KB Output is correct
64 Correct 435 ms 791088 KB Output is correct
65 Correct 452 ms 790608 KB Output is correct
66 Correct 423 ms 790612 KB Output is correct
67 Correct 444 ms 790864 KB Output is correct
68 Correct 425 ms 790616 KB Output is correct
69 Correct 447 ms 790100 KB Output is correct
70 Correct 425 ms 790608 KB Output is correct
71 Correct 424 ms 790232 KB Output is correct
72 Correct 432 ms 790356 KB Output is correct