#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
long long N, S[400005], P[400005], W[400005], L[400005];
vector<long long> vals;
pair<long long,long long> par[7][400005][25];
void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) {
N = n;
for (long long i = 0; i < N; ++i)
S[i] = s[i], P[i] = p[i], W[i] = w[i], L[i] = l[i], vals.push_back(S[i]);
sort(vals.begin(),vals.end());
vals.resize(unique(vals.begin(),vals.end()) - vals.begin());
vals.push_back(4e18);
for (long long i = 0; i < vals.size(); ++i) {
par[i][N][0] = make_pair(-1,-1);
for (long long j = 0; j < N; ++j) {
if (vals[i] > S[j]) par[i][j][0] = make_pair(W[j],S[j]);
else par[i][j][0] = make_pair(L[j],P[j]);
}
for (long long k = 1; k < 25; ++k) for (long long j = 0; j <= N; ++j) {
if (par[i][j][k-1] == make_pair(-1ll,-1ll)) par[i][j][k] = make_pair(-1,-1);
else {
par[i][j][k].first = par[i][par[i][j][k-1].first][k-1].first;
if (par[i][j][k].first == -1) par[i][j][k].second = -1;
else par[i][j][k].second = par[i][j][k-1].second + par[i][par[i][j][k-1].first][k-1].second;
}
}
}
}
long long simulate(int x, int z) {
long long ans = z;
for (long long i = 0; i < vals.size(); ++i) {
for (long long k = 24; k >= 0; --k)
if (par[i][x][k] != make_pair(-1ll,-1ll) && ans+par[i][x][k].second < vals[i])
ans += par[i][x][k].second, x = par[i][x][k].first;
if (x == N) return ans;
if (ans < vals[i]) ans += par[i][x][0].second, x = par[i][x][0].first;
}
return ans;
}
Compilation message
dungeons.cpp: In function 'void init(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
dungeons.cpp:16:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for (long long i = 0; i < vals.size(); ++i) {
| ~~^~~~~~~~~~~~~
dungeons.cpp: In function 'long long int simulate(int, int)':
dungeons.cpp:35:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (long long i = 0; i < vals.size(); ++i) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Runtime error |
10 ms |
468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
16 ms |
5204 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1236 KB |
Output is correct |
2 |
Correct |
88 ms |
43868 KB |
Output is correct |
3 |
Correct |
129 ms |
43876 KB |
Output is correct |
4 |
Correct |
100 ms |
44628 KB |
Output is correct |
5 |
Correct |
90 ms |
44644 KB |
Output is correct |
6 |
Correct |
84 ms |
44568 KB |
Output is correct |
7 |
Correct |
98 ms |
44736 KB |
Output is correct |
8 |
Correct |
96 ms |
44644 KB |
Output is correct |
9 |
Correct |
90 ms |
44568 KB |
Output is correct |
10 |
Correct |
96 ms |
44612 KB |
Output is correct |
11 |
Correct |
112 ms |
44644 KB |
Output is correct |
12 |
Correct |
175 ms |
45236 KB |
Output is correct |
13 |
Correct |
133 ms |
45128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1236 KB |
Output is correct |
2 |
Correct |
88 ms |
43868 KB |
Output is correct |
3 |
Correct |
129 ms |
43876 KB |
Output is correct |
4 |
Correct |
100 ms |
44628 KB |
Output is correct |
5 |
Correct |
90 ms |
44644 KB |
Output is correct |
6 |
Correct |
84 ms |
44568 KB |
Output is correct |
7 |
Correct |
98 ms |
44736 KB |
Output is correct |
8 |
Correct |
96 ms |
44644 KB |
Output is correct |
9 |
Correct |
90 ms |
44568 KB |
Output is correct |
10 |
Correct |
96 ms |
44612 KB |
Output is correct |
11 |
Correct |
112 ms |
44644 KB |
Output is correct |
12 |
Correct |
175 ms |
45236 KB |
Output is correct |
13 |
Correct |
133 ms |
45128 KB |
Output is correct |
14 |
Correct |
2 ms |
2388 KB |
Output is correct |
15 |
Correct |
144 ms |
84508 KB |
Output is correct |
16 |
Correct |
205 ms |
104320 KB |
Output is correct |
17 |
Correct |
216 ms |
123360 KB |
Output is correct |
18 |
Correct |
215 ms |
123360 KB |
Output is correct |
19 |
Correct |
182 ms |
123484 KB |
Output is correct |
20 |
Correct |
152 ms |
84072 KB |
Output is correct |
21 |
Correct |
189 ms |
103800 KB |
Output is correct |
22 |
Correct |
129 ms |
64576 KB |
Output is correct |
23 |
Correct |
175 ms |
103808 KB |
Output is correct |
24 |
Correct |
211 ms |
84336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1236 KB |
Output is correct |
2 |
Correct |
88 ms |
43868 KB |
Output is correct |
3 |
Correct |
129 ms |
43876 KB |
Output is correct |
4 |
Correct |
100 ms |
44628 KB |
Output is correct |
5 |
Correct |
90 ms |
44644 KB |
Output is correct |
6 |
Correct |
84 ms |
44568 KB |
Output is correct |
7 |
Correct |
98 ms |
44736 KB |
Output is correct |
8 |
Correct |
96 ms |
44644 KB |
Output is correct |
9 |
Correct |
90 ms |
44568 KB |
Output is correct |
10 |
Correct |
96 ms |
44612 KB |
Output is correct |
11 |
Correct |
112 ms |
44644 KB |
Output is correct |
12 |
Correct |
175 ms |
45236 KB |
Output is correct |
13 |
Correct |
133 ms |
45128 KB |
Output is correct |
14 |
Correct |
2 ms |
2388 KB |
Output is correct |
15 |
Correct |
144 ms |
84508 KB |
Output is correct |
16 |
Correct |
205 ms |
104320 KB |
Output is correct |
17 |
Correct |
216 ms |
123360 KB |
Output is correct |
18 |
Correct |
215 ms |
123360 KB |
Output is correct |
19 |
Correct |
182 ms |
123484 KB |
Output is correct |
20 |
Correct |
152 ms |
84072 KB |
Output is correct |
21 |
Correct |
189 ms |
103800 KB |
Output is correct |
22 |
Correct |
129 ms |
64576 KB |
Output is correct |
23 |
Correct |
175 ms |
103808 KB |
Output is correct |
24 |
Correct |
211 ms |
84336 KB |
Output is correct |
25 |
Runtime error |
221 ms |
222924 KB |
Execution killed with signal 11 |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
16 ms |
5204 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |