#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
const int N = 4e5+1;
const int lg = 25;
const int lgb = 12;
const int base = 4;
const int inf = 2e9;
int up[lg][N][lgb];
int min_diff[lg][N][lgb];
long long sum[lg][N][lgb];
int n;
vector<int> s, p, w, l;
void init(int nn, std::vector<int> ss, std::vector<int> pp,
std::vector<int> ww, std::vector<int> ll) {
n = nn;
swap(ss, s);
swap(pp, p);
swap(ww, w);
swap(ll, l);
for(int i = 0;i<n;i++) {
int _=0;
for(_ = 0;(1ll<<_)<=s[i];_++) {
up[_][i][0] = l[i];
min_diff[_][i][0] = s[i];
sum[_][i][0] = p[i];
}
for(;_<lg;_++) {
up[_][i][0] = w[i];
min_diff[_][i][0] = inf;
sum[_][i][0] = s[i];
}
}
for(int _ = 0;_<lg;_++) {
up[_][n][0] = n;
min_diff[_][n][0] = inf;
sum[_][n][0] = 0;
}
for(int _ = 0;_<lg;_++) {
for(int l = 1;l<lgb;l++) {
for(int i = 0;i<=n;i++) {
int at = i;
min_diff[_][i][l]=inf;
for(int k = 0;k<base;k++) {
if(min_diff[_][at][l-1] != inf)
min_diff[_][i][l] = max(0ll, min((long long)min_diff[_][i][l], min_diff[_][at][l-1]-sum[_][i][l]));
sum[_][i][l]+=sum[_][at][l-1];
at=up[_][at][l-1];
}
up[_][i][l] = at;
}
}
}
return;
}
long long simulate(int x, int zz) {
long long z = zz;
int cnt=0;
int idx=0;
while(1) {
if(x == n)break;
cnt++;
while((1ll<<idx) <= z) {
idx++;
}
int ll = min(lg-1, idx-1);
for(int j = lgb-1;j>=0;j--) {
for(int _ = 1;_<base;_++) {
if(up[ll][x][j] == n or (ll < lg-1 and min_diff[ll][x][j] <= z))continue;
z += sum[ll][x][j];
x = up[ll][x][j];
if(z >= (1ll<<idx))break;
}
}
if(s[x] <= z) {
z+=s[x];
x=w[x];
}
else if(s[x] > z) {
z+=p[x];
x=l[x];
}
}
return z;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
11100 KB |
Output is correct |
2 |
Correct |
1 ms |
9052 KB |
Output is correct |
3 |
Correct |
10 ms |
12448 KB |
Output is correct |
4 |
Correct |
235 ms |
238408 KB |
Output is correct |
5 |
Correct |
8 ms |
18264 KB |
Output is correct |
6 |
Correct |
242 ms |
243540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
13660 KB |
Output is correct |
2 |
Correct |
2051 ms |
1892672 KB |
Output is correct |
3 |
Correct |
1978 ms |
1892620 KB |
Output is correct |
4 |
Correct |
2041 ms |
1892672 KB |
Output is correct |
5 |
Correct |
1999 ms |
1892688 KB |
Output is correct |
6 |
Correct |
2152 ms |
1892692 KB |
Output is correct |
7 |
Correct |
1985 ms |
1892672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
13660 KB |
Output is correct |
2 |
Correct |
296 ms |
244744 KB |
Output is correct |
3 |
Correct |
230 ms |
244560 KB |
Output is correct |
4 |
Correct |
202 ms |
244308 KB |
Output is correct |
5 |
Correct |
200 ms |
244228 KB |
Output is correct |
6 |
Correct |
335 ms |
244356 KB |
Output is correct |
7 |
Correct |
313 ms |
244308 KB |
Output is correct |
8 |
Correct |
238 ms |
244308 KB |
Output is correct |
9 |
Correct |
219 ms |
244172 KB |
Output is correct |
10 |
Correct |
232 ms |
244640 KB |
Output is correct |
11 |
Correct |
441 ms |
244076 KB |
Output is correct |
12 |
Correct |
617 ms |
239844 KB |
Output is correct |
13 |
Correct |
319 ms |
244304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
13660 KB |
Output is correct |
2 |
Correct |
296 ms |
244744 KB |
Output is correct |
3 |
Correct |
230 ms |
244560 KB |
Output is correct |
4 |
Correct |
202 ms |
244308 KB |
Output is correct |
5 |
Correct |
200 ms |
244228 KB |
Output is correct |
6 |
Correct |
335 ms |
244356 KB |
Output is correct |
7 |
Correct |
313 ms |
244308 KB |
Output is correct |
8 |
Correct |
238 ms |
244308 KB |
Output is correct |
9 |
Correct |
219 ms |
244172 KB |
Output is correct |
10 |
Correct |
232 ms |
244640 KB |
Output is correct |
11 |
Correct |
441 ms |
244076 KB |
Output is correct |
12 |
Correct |
617 ms |
239844 KB |
Output is correct |
13 |
Correct |
319 ms |
244304 KB |
Output is correct |
14 |
Correct |
5 ms |
13660 KB |
Output is correct |
15 |
Correct |
260 ms |
244184 KB |
Output is correct |
16 |
Correct |
304 ms |
244300 KB |
Output is correct |
17 |
Correct |
229 ms |
244308 KB |
Output is correct |
18 |
Correct |
234 ms |
244184 KB |
Output is correct |
19 |
Correct |
343 ms |
238416 KB |
Output is correct |
20 |
Correct |
245 ms |
238416 KB |
Output is correct |
21 |
Correct |
273 ms |
238420 KB |
Output is correct |
22 |
Correct |
235 ms |
244052 KB |
Output is correct |
23 |
Correct |
420 ms |
240868 KB |
Output is correct |
24 |
Correct |
576 ms |
238468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
13660 KB |
Output is correct |
2 |
Correct |
296 ms |
244744 KB |
Output is correct |
3 |
Correct |
230 ms |
244560 KB |
Output is correct |
4 |
Correct |
202 ms |
244308 KB |
Output is correct |
5 |
Correct |
200 ms |
244228 KB |
Output is correct |
6 |
Correct |
335 ms |
244356 KB |
Output is correct |
7 |
Correct |
313 ms |
244308 KB |
Output is correct |
8 |
Correct |
238 ms |
244308 KB |
Output is correct |
9 |
Correct |
219 ms |
244172 KB |
Output is correct |
10 |
Correct |
232 ms |
244640 KB |
Output is correct |
11 |
Correct |
441 ms |
244076 KB |
Output is correct |
12 |
Correct |
617 ms |
239844 KB |
Output is correct |
13 |
Correct |
319 ms |
244304 KB |
Output is correct |
14 |
Correct |
5 ms |
13660 KB |
Output is correct |
15 |
Correct |
260 ms |
244184 KB |
Output is correct |
16 |
Correct |
304 ms |
244300 KB |
Output is correct |
17 |
Correct |
229 ms |
244308 KB |
Output is correct |
18 |
Correct |
234 ms |
244184 KB |
Output is correct |
19 |
Correct |
343 ms |
238416 KB |
Output is correct |
20 |
Correct |
245 ms |
238416 KB |
Output is correct |
21 |
Correct |
273 ms |
238420 KB |
Output is correct |
22 |
Correct |
235 ms |
244052 KB |
Output is correct |
23 |
Correct |
420 ms |
240868 KB |
Output is correct |
24 |
Correct |
576 ms |
238468 KB |
Output is correct |
25 |
Correct |
282 ms |
237268 KB |
Output is correct |
26 |
Correct |
320 ms |
238564 KB |
Output is correct |
27 |
Correct |
266 ms |
238416 KB |
Output is correct |
28 |
Correct |
260 ms |
239856 KB |
Output is correct |
29 |
Correct |
318 ms |
244368 KB |
Output is correct |
30 |
Correct |
290 ms |
244816 KB |
Output is correct |
31 |
Correct |
290 ms |
244304 KB |
Output is correct |
32 |
Correct |
486 ms |
244284 KB |
Output is correct |
33 |
Correct |
331 ms |
244248 KB |
Output is correct |
34 |
Correct |
556 ms |
244816 KB |
Output is correct |
35 |
Correct |
424 ms |
244308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
13660 KB |
Output is correct |
2 |
Correct |
2051 ms |
1892672 KB |
Output is correct |
3 |
Correct |
1978 ms |
1892620 KB |
Output is correct |
4 |
Correct |
2041 ms |
1892672 KB |
Output is correct |
5 |
Correct |
1999 ms |
1892688 KB |
Output is correct |
6 |
Correct |
2152 ms |
1892692 KB |
Output is correct |
7 |
Correct |
1985 ms |
1892672 KB |
Output is correct |
8 |
Correct |
5 ms |
13660 KB |
Output is correct |
9 |
Correct |
296 ms |
244744 KB |
Output is correct |
10 |
Correct |
230 ms |
244560 KB |
Output is correct |
11 |
Correct |
202 ms |
244308 KB |
Output is correct |
12 |
Correct |
200 ms |
244228 KB |
Output is correct |
13 |
Correct |
335 ms |
244356 KB |
Output is correct |
14 |
Correct |
313 ms |
244308 KB |
Output is correct |
15 |
Correct |
238 ms |
244308 KB |
Output is correct |
16 |
Correct |
219 ms |
244172 KB |
Output is correct |
17 |
Correct |
232 ms |
244640 KB |
Output is correct |
18 |
Correct |
441 ms |
244076 KB |
Output is correct |
19 |
Correct |
617 ms |
239844 KB |
Output is correct |
20 |
Correct |
319 ms |
244304 KB |
Output is correct |
21 |
Correct |
5 ms |
13660 KB |
Output is correct |
22 |
Correct |
260 ms |
244184 KB |
Output is correct |
23 |
Correct |
304 ms |
244300 KB |
Output is correct |
24 |
Correct |
229 ms |
244308 KB |
Output is correct |
25 |
Correct |
234 ms |
244184 KB |
Output is correct |
26 |
Correct |
343 ms |
238416 KB |
Output is correct |
27 |
Correct |
245 ms |
238416 KB |
Output is correct |
28 |
Correct |
273 ms |
238420 KB |
Output is correct |
29 |
Correct |
235 ms |
244052 KB |
Output is correct |
30 |
Correct |
420 ms |
240868 KB |
Output is correct |
31 |
Correct |
576 ms |
238468 KB |
Output is correct |
32 |
Correct |
282 ms |
237268 KB |
Output is correct |
33 |
Correct |
320 ms |
238564 KB |
Output is correct |
34 |
Correct |
266 ms |
238416 KB |
Output is correct |
35 |
Correct |
260 ms |
239856 KB |
Output is correct |
36 |
Correct |
318 ms |
244368 KB |
Output is correct |
37 |
Correct |
290 ms |
244816 KB |
Output is correct |
38 |
Correct |
290 ms |
244304 KB |
Output is correct |
39 |
Correct |
486 ms |
244284 KB |
Output is correct |
40 |
Correct |
331 ms |
244248 KB |
Output is correct |
41 |
Correct |
556 ms |
244816 KB |
Output is correct |
42 |
Correct |
424 ms |
244308 KB |
Output is correct |
43 |
Correct |
1 ms |
9048 KB |
Output is correct |
44 |
Correct |
5 ms |
13656 KB |
Output is correct |
45 |
Correct |
3588 ms |
1892664 KB |
Output is correct |
46 |
Correct |
2274 ms |
1892668 KB |
Output is correct |
47 |
Correct |
2297 ms |
1892796 KB |
Output is correct |
48 |
Correct |
2156 ms |
1892948 KB |
Output is correct |
49 |
Correct |
3802 ms |
1892672 KB |
Output is correct |
50 |
Correct |
2090 ms |
1892676 KB |
Output is correct |
51 |
Correct |
2380 ms |
1892952 KB |
Output is correct |
52 |
Correct |
2086 ms |
1892688 KB |
Output is correct |
53 |
Execution timed out |
7169 ms |
1892404 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |