#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define mk make_pair
typedef pair <ll, ll> pii;
const int N = 400023, LG = 24, L2 = 9, K = 7;
int s[N], p[N], o[N], l[N], n;
long long m[N], a[N];
pair <int, pii> nx[LG][N][L2];
const ll INF = 1e18;
void init(int nn, std::vector<int> ss, std::vector<int> pp, std::vector<int> ww, std::vector<int> ll) {
n = nn;
for (int i = 0; i < n; i++) {
s[i] = ss[i];
p[i] = pp[i];
o[i] = ww[i];
l[i] = ll[i];
}
m[n] = 0;
a[n] = 0;
l[n] = n;
o[n] = n;
s[n] = 0;
for (int i = n - 1; i >= 0; i--) {
a[i] = a[o[i]] + s[i];
m[i] = max((long long)s[i], m[o[i]] - s[i]);
}
for (int w = 0; w < LG; w++) {
for (int i = 0; i <= n; i++) {
if (i < n && s[i] <= (1 << w)) {
nx[w][i][0].F = o[i];
nx[w][i][0].S.F = INF;
nx[w][i][0].S.S = s[i];
} else {
nx[w][i][0].F = l[i];
nx[w][i][0].S.F = s[i] - 1;
nx[w][i][0].S.S = p[i];
}
}
for (int j = 1; j < L2; j++) {
for (int i = 0; i <= n; i++) {
nx[w][i][j].S.S = nx[w][i][j - 1].S.S;
nx[w][i][j].S.F = nx[w][i][j - 1].S.F;
nx[w][i][j].F = nx[w][i][j - 1].F;
for (int k = 0; k < K; k++) {
int y = nx[w][i][j].F;
nx[w][i][j].F = nx[w][y][j - 1].F;
nx[w][i][j].S.F = min (nx[w][i][j].S.F, nx[w][y][j - 1].S.F - nx[w][i][j].S.S);
nx[w][i][j].S.S = nx[w][i][j].S.S + nx[w][y][j - 1].S.S;
}
}
}
}
return;
}
pair <int, long long> findd (int w, int x, ll z) {
for (int i = L2 - 1; i >= 0; i--) {
for (int k = 0; k < K; k++) {
if (z <= nx[w][x][i].S.F) {
z += nx[w][x][i].S.S;
x = nx[w][x][i].F;
}
}
}
return {x, z};
}
ll ans (int x, ll z) {
if (z >= m[x])
return z + a[x];
int l = 0;
while ((1 << l) < s[x])
l++;
pair <int, ll> pp = findd (l, x, z);
x = pp.F;
z = pp.S;
return ans (x, z);
}
long long simulate(int x, int z) {
pair <int, ll> pp = findd (0, x, z);
x = pp.F;
z = pp.S;
ll w = ans (x, z);
return w;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
57688 KB |
Output is correct |
2 |
Correct |
4 ms |
57692 KB |
Output is correct |
3 |
Correct |
10 ms |
68408 KB |
Output is correct |
4 |
Correct |
251 ms |
297168 KB |
Output is correct |
5 |
Correct |
12 ms |
68184 KB |
Output is correct |
6 |
Correct |
233 ms |
297044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
68188 KB |
Output is correct |
2 |
Correct |
4565 ms |
2059992 KB |
Output is correct |
3 |
Correct |
3802 ms |
2061956 KB |
Output is correct |
4 |
Correct |
3679 ms |
2062996 KB |
Output is correct |
5 |
Correct |
2875 ms |
2063096 KB |
Output is correct |
6 |
Correct |
4747 ms |
2061748 KB |
Output is correct |
7 |
Correct |
4110 ms |
2060240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
68320 KB |
Output is correct |
2 |
Correct |
301 ms |
301572 KB |
Output is correct |
3 |
Correct |
233 ms |
299076 KB |
Output is correct |
4 |
Correct |
241 ms |
300292 KB |
Output is correct |
5 |
Correct |
265 ms |
298168 KB |
Output is correct |
6 |
Correct |
297 ms |
300380 KB |
Output is correct |
7 |
Correct |
323 ms |
301212 KB |
Output is correct |
8 |
Correct |
235 ms |
299480 KB |
Output is correct |
9 |
Correct |
270 ms |
298680 KB |
Output is correct |
10 |
Correct |
256 ms |
299936 KB |
Output is correct |
11 |
Correct |
462 ms |
298416 KB |
Output is correct |
12 |
Correct |
741 ms |
300576 KB |
Output is correct |
13 |
Correct |
321 ms |
300372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
68320 KB |
Output is correct |
2 |
Correct |
301 ms |
301572 KB |
Output is correct |
3 |
Correct |
233 ms |
299076 KB |
Output is correct |
4 |
Correct |
241 ms |
300292 KB |
Output is correct |
5 |
Correct |
265 ms |
298168 KB |
Output is correct |
6 |
Correct |
297 ms |
300380 KB |
Output is correct |
7 |
Correct |
323 ms |
301212 KB |
Output is correct |
8 |
Correct |
235 ms |
299480 KB |
Output is correct |
9 |
Correct |
270 ms |
298680 KB |
Output is correct |
10 |
Correct |
256 ms |
299936 KB |
Output is correct |
11 |
Correct |
462 ms |
298416 KB |
Output is correct |
12 |
Correct |
741 ms |
300576 KB |
Output is correct |
13 |
Correct |
321 ms |
300372 KB |
Output is correct |
14 |
Correct |
13 ms |
68188 KB |
Output is correct |
15 |
Correct |
254 ms |
299332 KB |
Output is correct |
16 |
Correct |
301 ms |
300608 KB |
Output is correct |
17 |
Correct |
261 ms |
300244 KB |
Output is correct |
18 |
Correct |
301 ms |
300372 KB |
Output is correct |
19 |
Correct |
285 ms |
300364 KB |
Output is correct |
20 |
Correct |
273 ms |
300220 KB |
Output is correct |
21 |
Correct |
271 ms |
300372 KB |
Output is correct |
22 |
Correct |
255 ms |
300292 KB |
Output is correct |
23 |
Correct |
446 ms |
300528 KB |
Output is correct |
24 |
Correct |
564 ms |
300628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
68320 KB |
Output is correct |
2 |
Correct |
301 ms |
301572 KB |
Output is correct |
3 |
Correct |
233 ms |
299076 KB |
Output is correct |
4 |
Correct |
241 ms |
300292 KB |
Output is correct |
5 |
Correct |
265 ms |
298168 KB |
Output is correct |
6 |
Correct |
297 ms |
300380 KB |
Output is correct |
7 |
Correct |
323 ms |
301212 KB |
Output is correct |
8 |
Correct |
235 ms |
299480 KB |
Output is correct |
9 |
Correct |
270 ms |
298680 KB |
Output is correct |
10 |
Correct |
256 ms |
299936 KB |
Output is correct |
11 |
Correct |
462 ms |
298416 KB |
Output is correct |
12 |
Correct |
741 ms |
300576 KB |
Output is correct |
13 |
Correct |
321 ms |
300372 KB |
Output is correct |
14 |
Correct |
13 ms |
68188 KB |
Output is correct |
15 |
Correct |
254 ms |
299332 KB |
Output is correct |
16 |
Correct |
301 ms |
300608 KB |
Output is correct |
17 |
Correct |
261 ms |
300244 KB |
Output is correct |
18 |
Correct |
301 ms |
300372 KB |
Output is correct |
19 |
Correct |
285 ms |
300364 KB |
Output is correct |
20 |
Correct |
273 ms |
300220 KB |
Output is correct |
21 |
Correct |
271 ms |
300372 KB |
Output is correct |
22 |
Correct |
255 ms |
300292 KB |
Output is correct |
23 |
Correct |
446 ms |
300528 KB |
Output is correct |
24 |
Correct |
564 ms |
300628 KB |
Output is correct |
25 |
Correct |
284 ms |
299736 KB |
Output is correct |
26 |
Correct |
325 ms |
300624 KB |
Output is correct |
27 |
Correct |
252 ms |
300352 KB |
Output is correct |
28 |
Correct |
257 ms |
300352 KB |
Output is correct |
29 |
Correct |
291 ms |
300544 KB |
Output is correct |
30 |
Correct |
326 ms |
300464 KB |
Output is correct |
31 |
Correct |
325 ms |
300116 KB |
Output is correct |
32 |
Correct |
545 ms |
300368 KB |
Output is correct |
33 |
Correct |
390 ms |
300452 KB |
Output is correct |
34 |
Correct |
519 ms |
300328 KB |
Output is correct |
35 |
Correct |
371 ms |
300300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
68188 KB |
Output is correct |
2 |
Correct |
4565 ms |
2059992 KB |
Output is correct |
3 |
Correct |
3802 ms |
2061956 KB |
Output is correct |
4 |
Correct |
3679 ms |
2062996 KB |
Output is correct |
5 |
Correct |
2875 ms |
2063096 KB |
Output is correct |
6 |
Correct |
4747 ms |
2061748 KB |
Output is correct |
7 |
Correct |
4110 ms |
2060240 KB |
Output is correct |
8 |
Correct |
9 ms |
68320 KB |
Output is correct |
9 |
Correct |
301 ms |
301572 KB |
Output is correct |
10 |
Correct |
233 ms |
299076 KB |
Output is correct |
11 |
Correct |
241 ms |
300292 KB |
Output is correct |
12 |
Correct |
265 ms |
298168 KB |
Output is correct |
13 |
Correct |
297 ms |
300380 KB |
Output is correct |
14 |
Correct |
323 ms |
301212 KB |
Output is correct |
15 |
Correct |
235 ms |
299480 KB |
Output is correct |
16 |
Correct |
270 ms |
298680 KB |
Output is correct |
17 |
Correct |
256 ms |
299936 KB |
Output is correct |
18 |
Correct |
462 ms |
298416 KB |
Output is correct |
19 |
Correct |
741 ms |
300576 KB |
Output is correct |
20 |
Correct |
321 ms |
300372 KB |
Output is correct |
21 |
Correct |
13 ms |
68188 KB |
Output is correct |
22 |
Correct |
254 ms |
299332 KB |
Output is correct |
23 |
Correct |
301 ms |
300608 KB |
Output is correct |
24 |
Correct |
261 ms |
300244 KB |
Output is correct |
25 |
Correct |
301 ms |
300372 KB |
Output is correct |
26 |
Correct |
285 ms |
300364 KB |
Output is correct |
27 |
Correct |
273 ms |
300220 KB |
Output is correct |
28 |
Correct |
271 ms |
300372 KB |
Output is correct |
29 |
Correct |
255 ms |
300292 KB |
Output is correct |
30 |
Correct |
446 ms |
300528 KB |
Output is correct |
31 |
Correct |
564 ms |
300628 KB |
Output is correct |
32 |
Correct |
284 ms |
299736 KB |
Output is correct |
33 |
Correct |
325 ms |
300624 KB |
Output is correct |
34 |
Correct |
252 ms |
300352 KB |
Output is correct |
35 |
Correct |
257 ms |
300352 KB |
Output is correct |
36 |
Correct |
291 ms |
300544 KB |
Output is correct |
37 |
Correct |
326 ms |
300464 KB |
Output is correct |
38 |
Correct |
325 ms |
300116 KB |
Output is correct |
39 |
Correct |
545 ms |
300368 KB |
Output is correct |
40 |
Correct |
390 ms |
300452 KB |
Output is correct |
41 |
Correct |
519 ms |
300328 KB |
Output is correct |
42 |
Correct |
371 ms |
300300 KB |
Output is correct |
43 |
Correct |
4 ms |
57692 KB |
Output is correct |
44 |
Correct |
8 ms |
68188 KB |
Output is correct |
45 |
Correct |
4479 ms |
2064992 KB |
Output is correct |
46 |
Correct |
3091 ms |
2061272 KB |
Output is correct |
47 |
Correct |
3272 ms |
2061476 KB |
Output is correct |
48 |
Correct |
3156 ms |
2063168 KB |
Output is correct |
49 |
Correct |
5174 ms |
2064968 KB |
Output is correct |
50 |
Correct |
4509 ms |
2062852 KB |
Output is correct |
51 |
Correct |
2773 ms |
2063472 KB |
Output is correct |
52 |
Correct |
4340 ms |
2061084 KB |
Output is correct |
53 |
Execution timed out |
7064 ms |
964192 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |