#include <bits/stdc++.h>
#include "dungeons.h"
using namespace std;
#define ll long long
#define inf 1e12
const int mxn = 1e5 + 10, LOG1 = 19, LOG2 = 27;
// steps, pwr
int n;
vector<int> s, p, w, l;
int go[mxn][LOG1][LOG2];
ll gain[mxn][LOG1][LOG2], lim[mxn][LOG1][LOG2];
void init(int _n, vector<int> _s, vector<int> _p, vector<int> _w, vector<int> _l) {
n = _n, s = _s, p = _p, w = _w, l = _l;
for (int pwr = 0; pwr < LOG2; pwr++) {
for (int i = 0; i < n; i++) {
if ((1LL << pwr) >= s[i]) {
if (w[i] == n) go[i][0][pwr] = -1;
else {
go[i][0][pwr] = w[i];
gain[i][0][pwr] = s[i];
lim[i][0][pwr] = inf;
}
}
else {
if (l[i] == n) go[i][0][pwr] = -1;
else {
go[i][0][pwr] = l[i];
gain[i][0][pwr] = p[i];
lim[i][0][pwr] = s[i];
}
}
}
}
for (int steps = 1; steps < LOG1; steps++) {
for (int pwr = 0; pwr < LOG2; pwr++) {
for (int i = 0; i < n; i++) {
int nxt = go[i][steps - 1][pwr];
if (go[i][steps - 1][pwr] == -1 || go[nxt][steps - 1][pwr] == -1) go[i][steps][pwr] = -1;
else {
go[i][steps][pwr] = go[nxt][steps - 1][pwr];
gain[i][steps][pwr] = gain[i][steps - 1][pwr] + gain[nxt][steps - 1][pwr];
lim[i][steps][pwr] = min(lim[i][steps - 1][pwr], lim[nxt][steps - 1][pwr] - gain[i][steps - 1][pwr]);
}
}
}
}
}
ll simulate(int x, int z) {
ll ans = z;
while (x != n) {
ll pwr = log2(ans);
for (int i = LOG1 - 1; i >= 0; i--) {
if (go[x][i][pwr] == -1) continue;
if (ans >= lim[x][i][pwr]) continue;
ans += gain[x][i][pwr];
x = go[x][i][pwr];
}
if (ans >= s[x]) {
ans += s[x];
x = w[x];
}
else {
ans += p[x];
x = l[x];
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
5 ms |
25180 KB |
Output is correct |
4 |
Correct |
384 ms |
507680 KB |
Output is correct |
5 |
Correct |
8 ms |
25180 KB |
Output is correct |
6 |
Correct |
391 ms |
507644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Runtime error |
630 ms |
1549368 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14940 KB |
Output is correct |
2 |
Correct |
477 ms |
507304 KB |
Output is correct |
3 |
Correct |
479 ms |
507472 KB |
Output is correct |
4 |
Correct |
469 ms |
507424 KB |
Output is correct |
5 |
Correct |
432 ms |
507472 KB |
Output is correct |
6 |
Correct |
508 ms |
507324 KB |
Output is correct |
7 |
Correct |
535 ms |
507456 KB |
Output is correct |
8 |
Correct |
437 ms |
507396 KB |
Output is correct |
9 |
Correct |
326 ms |
507372 KB |
Output is correct |
10 |
Correct |
452 ms |
507476 KB |
Output is correct |
11 |
Correct |
524 ms |
507728 KB |
Output is correct |
12 |
Correct |
2737 ms |
507472 KB |
Output is correct |
13 |
Correct |
2577 ms |
507480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14940 KB |
Output is correct |
2 |
Correct |
477 ms |
507304 KB |
Output is correct |
3 |
Correct |
479 ms |
507472 KB |
Output is correct |
4 |
Correct |
469 ms |
507424 KB |
Output is correct |
5 |
Correct |
432 ms |
507472 KB |
Output is correct |
6 |
Correct |
508 ms |
507324 KB |
Output is correct |
7 |
Correct |
535 ms |
507456 KB |
Output is correct |
8 |
Correct |
437 ms |
507396 KB |
Output is correct |
9 |
Correct |
326 ms |
507372 KB |
Output is correct |
10 |
Correct |
452 ms |
507476 KB |
Output is correct |
11 |
Correct |
524 ms |
507728 KB |
Output is correct |
12 |
Correct |
2737 ms |
507472 KB |
Output is correct |
13 |
Correct |
2577 ms |
507480 KB |
Output is correct |
14 |
Correct |
4 ms |
15192 KB |
Output is correct |
15 |
Correct |
475 ms |
507444 KB |
Output is correct |
16 |
Correct |
496 ms |
507460 KB |
Output is correct |
17 |
Correct |
460 ms |
507472 KB |
Output is correct |
18 |
Correct |
490 ms |
507476 KB |
Output is correct |
19 |
Correct |
483 ms |
507720 KB |
Output is correct |
20 |
Correct |
468 ms |
507524 KB |
Output is correct |
21 |
Correct |
490 ms |
507752 KB |
Output is correct |
22 |
Correct |
421 ms |
507472 KB |
Output is correct |
23 |
Correct |
548 ms |
507476 KB |
Output is correct |
24 |
Correct |
774 ms |
507516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14940 KB |
Output is correct |
2 |
Correct |
477 ms |
507304 KB |
Output is correct |
3 |
Correct |
479 ms |
507472 KB |
Output is correct |
4 |
Correct |
469 ms |
507424 KB |
Output is correct |
5 |
Correct |
432 ms |
507472 KB |
Output is correct |
6 |
Correct |
508 ms |
507324 KB |
Output is correct |
7 |
Correct |
535 ms |
507456 KB |
Output is correct |
8 |
Correct |
437 ms |
507396 KB |
Output is correct |
9 |
Correct |
326 ms |
507372 KB |
Output is correct |
10 |
Correct |
452 ms |
507476 KB |
Output is correct |
11 |
Correct |
524 ms |
507728 KB |
Output is correct |
12 |
Correct |
2737 ms |
507472 KB |
Output is correct |
13 |
Correct |
2577 ms |
507480 KB |
Output is correct |
14 |
Correct |
4 ms |
15192 KB |
Output is correct |
15 |
Correct |
475 ms |
507444 KB |
Output is correct |
16 |
Correct |
496 ms |
507460 KB |
Output is correct |
17 |
Correct |
460 ms |
507472 KB |
Output is correct |
18 |
Correct |
490 ms |
507476 KB |
Output is correct |
19 |
Correct |
483 ms |
507720 KB |
Output is correct |
20 |
Correct |
468 ms |
507524 KB |
Output is correct |
21 |
Correct |
490 ms |
507752 KB |
Output is correct |
22 |
Correct |
421 ms |
507472 KB |
Output is correct |
23 |
Correct |
548 ms |
507476 KB |
Output is correct |
24 |
Correct |
774 ms |
507516 KB |
Output is correct |
25 |
Correct |
491 ms |
506752 KB |
Output is correct |
26 |
Correct |
530 ms |
507528 KB |
Output is correct |
27 |
Correct |
490 ms |
507432 KB |
Output is correct |
28 |
Correct |
579 ms |
507488 KB |
Output is correct |
29 |
Correct |
571 ms |
507364 KB |
Output is correct |
30 |
Correct |
565 ms |
507476 KB |
Output is correct |
31 |
Correct |
570 ms |
507520 KB |
Output is correct |
32 |
Correct |
638 ms |
507516 KB |
Output is correct |
33 |
Correct |
695 ms |
507320 KB |
Output is correct |
34 |
Correct |
1337 ms |
507264 KB |
Output is correct |
35 |
Correct |
661 ms |
507760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Runtime error |
630 ms |
1549368 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |