#include <bits/stdc++.h>
#include "dungeons.h"
using namespace std;
typedef long long ll;
int n;
vector<int> p, w, l;
int s;
vector<vector<pair<ll, ll>>> jmp;
vector<ll> dp;
void init(int n1, vector<int> s1, vector<int> p1, vector<int> w1, vector<int> l1) {
n = n1; s = s1[0]; p = p1; w = w1; l = l1;
jmp = vector<vector<pair<ll, ll>>>(n, vector<pair<ll, ll>>(20));
for (int i = 0; i < n; i++) {
jmp[i][0] = {p[i], l[i]};
if (jmp[i][0].second == n) jmp[i][0].first = 1ll << 30ll;
}
for (int j = 1; j < 20; j++) {
for (int i = 0; i < n; i++) {
if (jmp[i][j-1].second == n) {
jmp[i][j] = jmp[i][j-1];
continue;
}
if (jmp[jmp[i][j-1].second][j-1].second == n) {
jmp[i][j] = {jmp[jmp[i][j-1].second][j-1].first,
jmp[jmp[i][j-1].second][j-1].second};
continue;
}
jmp[i][j] = {jmp[jmp[i][j-1].second][j-1].first + jmp[i][j-1].first,
jmp[jmp[i][j-1].second][j-1].second};
}
}
dp = vector<ll>(n+1);
dp[n] = 0;
for (int i = n-1; i >= 0; i--) {
dp[i] = s + dp[w[i]];
}
}
ll simulate(int x1, int z1) {
ll i = x1, z = z1;
if (i == n) return z;
for (int j = 20-1; j >= 0; j--) {
if (z + jmp[i][j].first < s) {
z += jmp[i][j].first;
i = jmp[i][j].second;
}
}
if (z < s) {
z += p[i];
i = l[i];
}
z += dp[i];
return z;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
860 KB |
Output is correct |
2 |
Correct |
32 ms |
21340 KB |
Output is correct |
3 |
Correct |
34 ms |
21216 KB |
Output is correct |
4 |
Correct |
30 ms |
21340 KB |
Output is correct |
5 |
Correct |
29 ms |
21220 KB |
Output is correct |
6 |
Correct |
39 ms |
21340 KB |
Output is correct |
7 |
Incorrect |
35 ms |
21340 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
860 KB |
Output is correct |
2 |
Correct |
32 ms |
21340 KB |
Output is correct |
3 |
Correct |
34 ms |
21216 KB |
Output is correct |
4 |
Correct |
30 ms |
21340 KB |
Output is correct |
5 |
Correct |
29 ms |
21220 KB |
Output is correct |
6 |
Correct |
39 ms |
21340 KB |
Output is correct |
7 |
Incorrect |
35 ms |
21340 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
860 KB |
Output is correct |
2 |
Correct |
32 ms |
21340 KB |
Output is correct |
3 |
Correct |
34 ms |
21216 KB |
Output is correct |
4 |
Correct |
30 ms |
21340 KB |
Output is correct |
5 |
Correct |
29 ms |
21220 KB |
Output is correct |
6 |
Correct |
39 ms |
21340 KB |
Output is correct |
7 |
Incorrect |
35 ms |
21340 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |