# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1058812 |
2024-08-14T14:03:00 Z |
Tonyl |
Trains (BOI24_trains) |
C++17 |
|
448 ms |
191916 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
#define REP(i,n) for (int i = 0; i < n; i++)
#define trav(a,x) for (auto& a : x)
#define D(x) cerr << #x << ": " << x << endl;
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
const int MAX_N = 1e5+1;
const int SQRT = 320;
struct Prefix {
vi pr = {0};
int q(int x) {
if (x <= 0) return 0;
int r = pr.back();
int l = pr.size()>x ? pr[pr.size()-1-x] : 0;
return (MOD+r-l)%MOD;
}
void add(int a) {
pr.push_back((pr.back()+a)%MOD);
}
};
struct Station {
int d, x;
};
Station stations[MAX_N];
Prefix prsq[SQRT][SQRT+1];
int totals[MAX_N];
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
REP(i,n) {
cin >> stations[i].d >> stations[i].x;
}
for (int i = n-1; i >= 0; i--) {
Station& st = stations[i];
int tot = 1;
if (st.d >= SQRT) {
int j = i+st.d;
while (j < n && st.x--) {
tot += totals[j];
j += st.d;
tot %= MOD;
}
} else if (st.d != 0) tot = prsq[st.d-1][i%st.d].q(st.x)+1;
for (int s = 0; s < SQRT; s++) {
int sq = s+1;
int md = i%sq;
prsq[s][md].add(tot);
}
totals[i] = tot;
}
cout << totals[0] << endl;
}
Compilation message
Main.cpp: In member function 'int Prefix::q(int)':
Main.cpp:21:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
21 | int l = pr.size()>x ? pr[pr.size()-1-x] : 0;
| ~~~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6232 KB |
Output is correct |
2 |
Correct |
3 ms |
6236 KB |
Output is correct |
3 |
Correct |
3 ms |
6312 KB |
Output is correct |
4 |
Correct |
3 ms |
6236 KB |
Output is correct |
5 |
Correct |
3 ms |
6236 KB |
Output is correct |
6 |
Correct |
3 ms |
6300 KB |
Output is correct |
7 |
Correct |
3 ms |
6236 KB |
Output is correct |
8 |
Correct |
3 ms |
6236 KB |
Output is correct |
9 |
Correct |
3 ms |
6236 KB |
Output is correct |
10 |
Correct |
5 ms |
6236 KB |
Output is correct |
11 |
Correct |
3 ms |
6236 KB |
Output is correct |
12 |
Correct |
4 ms |
6236 KB |
Output is correct |
13 |
Correct |
4 ms |
6236 KB |
Output is correct |
14 |
Correct |
3 ms |
6236 KB |
Output is correct |
15 |
Correct |
3 ms |
6236 KB |
Output is correct |
16 |
Correct |
3 ms |
6236 KB |
Output is correct |
17 |
Correct |
3 ms |
6192 KB |
Output is correct |
18 |
Correct |
3 ms |
6236 KB |
Output is correct |
19 |
Correct |
3 ms |
6236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6232 KB |
Output is correct |
2 |
Correct |
3 ms |
6236 KB |
Output is correct |
3 |
Correct |
3 ms |
6312 KB |
Output is correct |
4 |
Correct |
3 ms |
6236 KB |
Output is correct |
5 |
Correct |
3 ms |
6236 KB |
Output is correct |
6 |
Correct |
3 ms |
6300 KB |
Output is correct |
7 |
Correct |
3 ms |
6236 KB |
Output is correct |
8 |
Correct |
3 ms |
6236 KB |
Output is correct |
9 |
Correct |
3 ms |
6236 KB |
Output is correct |
10 |
Correct |
5 ms |
6236 KB |
Output is correct |
11 |
Correct |
3 ms |
6236 KB |
Output is correct |
12 |
Correct |
4 ms |
6236 KB |
Output is correct |
13 |
Correct |
4 ms |
6236 KB |
Output is correct |
14 |
Correct |
3 ms |
6236 KB |
Output is correct |
15 |
Correct |
3 ms |
6236 KB |
Output is correct |
16 |
Correct |
3 ms |
6236 KB |
Output is correct |
17 |
Correct |
3 ms |
6192 KB |
Output is correct |
18 |
Correct |
3 ms |
6236 KB |
Output is correct |
19 |
Correct |
3 ms |
6236 KB |
Output is correct |
20 |
Correct |
46 ms |
21188 KB |
Output is correct |
21 |
Correct |
21 ms |
11100 KB |
Output is correct |
22 |
Correct |
51 ms |
25240 KB |
Output is correct |
23 |
Correct |
40 ms |
17620 KB |
Output is correct |
24 |
Correct |
27 ms |
13136 KB |
Output is correct |
25 |
Correct |
44 ms |
22708 KB |
Output is correct |
26 |
Correct |
29 ms |
14076 KB |
Output is correct |
27 |
Correct |
44 ms |
21860 KB |
Output is correct |
28 |
Correct |
49 ms |
25384 KB |
Output is correct |
29 |
Correct |
49 ms |
25428 KB |
Output is correct |
30 |
Correct |
51 ms |
25424 KB |
Output is correct |
31 |
Correct |
53 ms |
25340 KB |
Output is correct |
32 |
Correct |
50 ms |
25428 KB |
Output is correct |
33 |
Correct |
49 ms |
25424 KB |
Output is correct |
34 |
Correct |
63 ms |
25428 KB |
Output is correct |
35 |
Correct |
49 ms |
25424 KB |
Output is correct |
36 |
Correct |
50 ms |
25416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
6236 KB |
Output is correct |
2 |
Correct |
36 ms |
17796 KB |
Output is correct |
3 |
Correct |
26 ms |
14160 KB |
Output is correct |
4 |
Correct |
47 ms |
21840 KB |
Output is correct |
5 |
Correct |
307 ms |
154948 KB |
Output is correct |
6 |
Correct |
448 ms |
190372 KB |
Output is correct |
7 |
Correct |
413 ms |
190408 KB |
Output is correct |
8 |
Correct |
3 ms |
6232 KB |
Output is correct |
9 |
Correct |
3 ms |
6236 KB |
Output is correct |
10 |
Correct |
3 ms |
6236 KB |
Output is correct |
11 |
Correct |
51 ms |
25412 KB |
Output is correct |
12 |
Correct |
424 ms |
190412 KB |
Output is correct |
13 |
Correct |
3 ms |
6236 KB |
Output is correct |
14 |
Correct |
58 ms |
25328 KB |
Output is correct |
15 |
Correct |
395 ms |
190536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
97844 KB |
Output is correct |
2 |
Correct |
171 ms |
85592 KB |
Output is correct |
3 |
Correct |
407 ms |
190412 KB |
Output is correct |
4 |
Correct |
305 ms |
141200 KB |
Output is correct |
5 |
Correct |
3 ms |
6232 KB |
Output is correct |
6 |
Correct |
3 ms |
6232 KB |
Output is correct |
7 |
Correct |
50 ms |
25428 KB |
Output is correct |
8 |
Correct |
433 ms |
190360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6232 KB |
Output is correct |
2 |
Correct |
3 ms |
6236 KB |
Output is correct |
3 |
Correct |
3 ms |
6312 KB |
Output is correct |
4 |
Correct |
3 ms |
6236 KB |
Output is correct |
5 |
Correct |
3 ms |
6236 KB |
Output is correct |
6 |
Correct |
3 ms |
6300 KB |
Output is correct |
7 |
Correct |
3 ms |
6236 KB |
Output is correct |
8 |
Correct |
3 ms |
6236 KB |
Output is correct |
9 |
Correct |
3 ms |
6236 KB |
Output is correct |
10 |
Correct |
5 ms |
6236 KB |
Output is correct |
11 |
Correct |
3 ms |
6236 KB |
Output is correct |
12 |
Correct |
4 ms |
6236 KB |
Output is correct |
13 |
Correct |
4 ms |
6236 KB |
Output is correct |
14 |
Correct |
3 ms |
6236 KB |
Output is correct |
15 |
Correct |
3 ms |
6236 KB |
Output is correct |
16 |
Correct |
3 ms |
6236 KB |
Output is correct |
17 |
Correct |
3 ms |
6192 KB |
Output is correct |
18 |
Correct |
3 ms |
6236 KB |
Output is correct |
19 |
Correct |
3 ms |
6236 KB |
Output is correct |
20 |
Correct |
46 ms |
21188 KB |
Output is correct |
21 |
Correct |
21 ms |
11100 KB |
Output is correct |
22 |
Correct |
51 ms |
25240 KB |
Output is correct |
23 |
Correct |
40 ms |
17620 KB |
Output is correct |
24 |
Correct |
27 ms |
13136 KB |
Output is correct |
25 |
Correct |
44 ms |
22708 KB |
Output is correct |
26 |
Correct |
29 ms |
14076 KB |
Output is correct |
27 |
Correct |
44 ms |
21860 KB |
Output is correct |
28 |
Correct |
49 ms |
25384 KB |
Output is correct |
29 |
Correct |
49 ms |
25428 KB |
Output is correct |
30 |
Correct |
51 ms |
25424 KB |
Output is correct |
31 |
Correct |
53 ms |
25340 KB |
Output is correct |
32 |
Correct |
50 ms |
25428 KB |
Output is correct |
33 |
Correct |
49 ms |
25424 KB |
Output is correct |
34 |
Correct |
63 ms |
25428 KB |
Output is correct |
35 |
Correct |
49 ms |
25424 KB |
Output is correct |
36 |
Correct |
50 ms |
25416 KB |
Output is correct |
37 |
Correct |
6 ms |
6236 KB |
Output is correct |
38 |
Correct |
36 ms |
17796 KB |
Output is correct |
39 |
Correct |
26 ms |
14160 KB |
Output is correct |
40 |
Correct |
47 ms |
21840 KB |
Output is correct |
41 |
Correct |
307 ms |
154948 KB |
Output is correct |
42 |
Correct |
448 ms |
190372 KB |
Output is correct |
43 |
Correct |
413 ms |
190408 KB |
Output is correct |
44 |
Correct |
3 ms |
6232 KB |
Output is correct |
45 |
Correct |
3 ms |
6236 KB |
Output is correct |
46 |
Correct |
3 ms |
6236 KB |
Output is correct |
47 |
Correct |
51 ms |
25412 KB |
Output is correct |
48 |
Correct |
424 ms |
190412 KB |
Output is correct |
49 |
Correct |
3 ms |
6236 KB |
Output is correct |
50 |
Correct |
58 ms |
25328 KB |
Output is correct |
51 |
Correct |
395 ms |
190536 KB |
Output is correct |
52 |
Correct |
217 ms |
97844 KB |
Output is correct |
53 |
Correct |
171 ms |
85592 KB |
Output is correct |
54 |
Correct |
407 ms |
190412 KB |
Output is correct |
55 |
Correct |
305 ms |
141200 KB |
Output is correct |
56 |
Correct |
3 ms |
6232 KB |
Output is correct |
57 |
Correct |
3 ms |
6232 KB |
Output is correct |
58 |
Correct |
50 ms |
25428 KB |
Output is correct |
59 |
Correct |
433 ms |
190360 KB |
Output is correct |
60 |
Correct |
336 ms |
167708 KB |
Output is correct |
61 |
Correct |
412 ms |
190408 KB |
Output is correct |
62 |
Correct |
401 ms |
190432 KB |
Output is correct |
63 |
Correct |
412 ms |
190408 KB |
Output is correct |
64 |
Correct |
402 ms |
190456 KB |
Output is correct |
65 |
Correct |
440 ms |
190412 KB |
Output is correct |
66 |
Correct |
408 ms |
191508 KB |
Output is correct |
67 |
Correct |
420 ms |
191916 KB |
Output is correct |
68 |
Correct |
407 ms |
191688 KB |
Output is correct |
69 |
Correct |
408 ms |
191024 KB |
Output is correct |
70 |
Correct |
401 ms |
191472 KB |
Output is correct |
71 |
Correct |
447 ms |
191432 KB |
Output is correct |
72 |
Correct |
411 ms |
191432 KB |
Output is correct |