#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;
int s[N], p[N], w[N], l[N], n;
long long m[N], a[N];
pair <int, pii> nx[N][LG];
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];
w[i] = ww[i];
l[i] = ll[i];
}
m[n] = 0;
a[n] = 0;
l[n] = n;
w[n] = n;
for (int i = n - 1; i >= 0; i--) {
a[i] = a[w[i]] + s[i];
m[i] = max((long long)s[i], m[w[i]] - s[i]);
}
for (int i = 0; i <= n; i++) {
nx[i][0].F = l[i];
nx[i][0].S.F = s[i] - 1;
nx[i][0].S.S = p[i];
}
for (int j = 1; j < LG; j++) {
for (int i = 0; i <= n; i++) {
int w = nx[i][j - 1].F;
nx[i][j].F = nx[w][j - 1].F;
nx[i][j].S.S = nx[i][j - 1].S.S + nx[w][j - 1].S.S;
nx[i][j].S.F = min (nx[i][j - 1].S.F, nx[w][j - 1].S.F - nx[i][j - 1].S.S);
}
}
return;
}
pair <int, long long> find (int x, ll z) {
for (int i = LG - 1; i >= 0; i--) {
if (z <= nx[x][i].S.F) {
z += nx[x][i].S.S;
x = nx[x][i].F;
}
}
return {x, z};
}
int c = 0;
ll ans (int x, ll z) {
if (z >= m[x])
return z + a[x];
c++;
if (z >= s[x]) {
z += s[x];
x = w[x];
} else {
pair <int, long long> p = find (x, z);
z = p.S;
x = p.F;
if (x == n)
return z;
z += s[x];
x = w[x];
}
return ans (x, z);
}
long long simulate(int x, int z) {
c = 0;
ll w = ans (x, z);
return w;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
12892 KB |
Output is correct |
4 |
Correct |
18 ms |
41172 KB |
Output is correct |
5 |
Correct |
2 ms |
12888 KB |
Output is correct |
6 |
Correct |
17 ms |
41172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
12892 KB |
Output is correct |
2 |
Execution timed out |
7064 ms |
251476 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
12892 KB |
Output is correct |
2 |
Correct |
28 ms |
42112 KB |
Output is correct |
3 |
Correct |
29 ms |
42128 KB |
Output is correct |
4 |
Correct |
25 ms |
42072 KB |
Output is correct |
5 |
Correct |
28 ms |
42072 KB |
Output is correct |
6 |
Correct |
30 ms |
42076 KB |
Output is correct |
7 |
Correct |
31 ms |
42076 KB |
Output is correct |
8 |
Correct |
25 ms |
41980 KB |
Output is correct |
9 |
Correct |
25 ms |
42072 KB |
Output is correct |
10 |
Correct |
24 ms |
42076 KB |
Output is correct |
11 |
Correct |
32 ms |
42076 KB |
Output is correct |
12 |
Correct |
42 ms |
42076 KB |
Output is correct |
13 |
Correct |
36 ms |
42072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
12892 KB |
Output is correct |
2 |
Correct |
28 ms |
42112 KB |
Output is correct |
3 |
Correct |
29 ms |
42128 KB |
Output is correct |
4 |
Correct |
25 ms |
42072 KB |
Output is correct |
5 |
Correct |
28 ms |
42072 KB |
Output is correct |
6 |
Correct |
30 ms |
42076 KB |
Output is correct |
7 |
Correct |
31 ms |
42076 KB |
Output is correct |
8 |
Correct |
25 ms |
41980 KB |
Output is correct |
9 |
Correct |
25 ms |
42072 KB |
Output is correct |
10 |
Correct |
24 ms |
42076 KB |
Output is correct |
11 |
Correct |
32 ms |
42076 KB |
Output is correct |
12 |
Correct |
42 ms |
42076 KB |
Output is correct |
13 |
Correct |
36 ms |
42072 KB |
Output is correct |
14 |
Correct |
2 ms |
12888 KB |
Output is correct |
15 |
Correct |
111 ms |
41964 KB |
Output is correct |
16 |
Correct |
29 ms |
42076 KB |
Output is correct |
17 |
Correct |
25 ms |
42076 KB |
Output is correct |
18 |
Correct |
148 ms |
41968 KB |
Output is correct |
19 |
Correct |
33 ms |
42076 KB |
Output is correct |
20 |
Correct |
36 ms |
42076 KB |
Output is correct |
21 |
Correct |
111 ms |
42076 KB |
Output is correct |
22 |
Correct |
6605 ms |
42072 KB |
Output is correct |
23 |
Correct |
32 ms |
42076 KB |
Output is correct |
24 |
Execution timed out |
7087 ms |
42072 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
12892 KB |
Output is correct |
2 |
Correct |
28 ms |
42112 KB |
Output is correct |
3 |
Correct |
29 ms |
42128 KB |
Output is correct |
4 |
Correct |
25 ms |
42072 KB |
Output is correct |
5 |
Correct |
28 ms |
42072 KB |
Output is correct |
6 |
Correct |
30 ms |
42076 KB |
Output is correct |
7 |
Correct |
31 ms |
42076 KB |
Output is correct |
8 |
Correct |
25 ms |
41980 KB |
Output is correct |
9 |
Correct |
25 ms |
42072 KB |
Output is correct |
10 |
Correct |
24 ms |
42076 KB |
Output is correct |
11 |
Correct |
32 ms |
42076 KB |
Output is correct |
12 |
Correct |
42 ms |
42076 KB |
Output is correct |
13 |
Correct |
36 ms |
42072 KB |
Output is correct |
14 |
Correct |
2 ms |
12888 KB |
Output is correct |
15 |
Correct |
111 ms |
41964 KB |
Output is correct |
16 |
Correct |
29 ms |
42076 KB |
Output is correct |
17 |
Correct |
25 ms |
42076 KB |
Output is correct |
18 |
Correct |
148 ms |
41968 KB |
Output is correct |
19 |
Correct |
33 ms |
42076 KB |
Output is correct |
20 |
Correct |
36 ms |
42076 KB |
Output is correct |
21 |
Correct |
111 ms |
42076 KB |
Output is correct |
22 |
Correct |
6605 ms |
42072 KB |
Output is correct |
23 |
Correct |
32 ms |
42076 KB |
Output is correct |
24 |
Execution timed out |
7087 ms |
42072 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
12892 KB |
Output is correct |
2 |
Execution timed out |
7064 ms |
251476 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |