#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
const int sz=9;
const long long INF=1e18;
int nxt[400001][24][sz+1];
long long mx[400001][24],mn[400001][24][sz],sum[400001][24][sz+1];
vector <int> S,P,ve={1};
void init(int n, vector <int> s, vector <int> p, vector <int> w, vector <int> l){
S=s;
P=p;
for (int i=1;i<sz;i++)
ve.push_back(ve.back()*6);
memset(nxt,-1,sizeof(nxt));
for (int i=0;i<n;i++){
for (int j=0;j<sz;j++)
if (s[i]<=ve[j]){
nxt[i][0][j]=w[i];
sum[i][0][j]=s[i];
mn[i][0][j]=INF;
}
else{
nxt[i][0][j]=l[i];
sum[i][0][j]=p[i];
mn[i][0][j]=s[i];
}
nxt[i][0][sz]=w[i];
mx[i][0]=sum[i][0][sz]=s[i];
}
for (int j=1;j<24;j++){
for (int i=0;i<n;i++)
for (int k=0;k<=sz;k++){
if (nxt[i][j-1][k]==-1)
continue;
int u=nxt[i][j-1][k];
nxt[i][j][k]=nxt[u][j-1][k];
if (k<sz)
mn[i][j][k]=min(mn[i][j-1][k],mn[u][j-1][k]-sum[i][j-1][k]);
else
mx[i][j]=max(mx[i][j-1],mx[u][j-1]-sum[i][j-1][k]);
sum[i][j][k]=sum[i][j-1][k]+sum[u][j-1][k];
}
}
}
long long simulate(int x, int Z){
int b=0;
long long z=Z;
while (nxt[x][0][0]!=-1){
int j=(b?upper_bound(ve.begin(),ve.end(),z)-ve.begin()-1:sz);
for (int i=23;i>=0;i--)
if (nxt[x][i][j]!=-1)
if ((b&&z<mn[x][i][j])||(!b&&z>=mx[x][i])){
z+=sum[x][i][j];
x=nxt[x][i][j];
}
b^=1;
}
return z;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
380756 KB |
Output is correct |
2 |
Correct |
43 ms |
380752 KB |
Output is correct |
3 |
Correct |
45 ms |
387160 KB |
Output is correct |
4 |
Correct |
295 ms |
572756 KB |
Output is correct |
5 |
Correct |
46 ms |
387152 KB |
Output is correct |
6 |
Correct |
302 ms |
573008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
383060 KB |
Output is correct |
2 |
Correct |
3429 ms |
1895612 KB |
Output is correct |
3 |
Correct |
3368 ms |
1898860 KB |
Output is correct |
4 |
Correct |
3493 ms |
1898420 KB |
Output is correct |
5 |
Correct |
2740 ms |
1898056 KB |
Output is correct |
6 |
Correct |
3181 ms |
1902440 KB |
Output is correct |
7 |
Correct |
3161 ms |
1900624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
383060 KB |
Output is correct |
2 |
Correct |
337 ms |
574184 KB |
Output is correct |
3 |
Correct |
340 ms |
574360 KB |
Output is correct |
4 |
Correct |
283 ms |
574036 KB |
Output is correct |
5 |
Correct |
284 ms |
573524 KB |
Output is correct |
6 |
Correct |
352 ms |
573880 KB |
Output is correct |
7 |
Correct |
340 ms |
573932 KB |
Output is correct |
8 |
Correct |
285 ms |
573524 KB |
Output is correct |
9 |
Correct |
227 ms |
573680 KB |
Output is correct |
10 |
Correct |
291 ms |
573544 KB |
Output is correct |
11 |
Correct |
347 ms |
573928 KB |
Output is correct |
12 |
Correct |
526 ms |
573936 KB |
Output is correct |
13 |
Correct |
445 ms |
573932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
383060 KB |
Output is correct |
2 |
Correct |
337 ms |
574184 KB |
Output is correct |
3 |
Correct |
340 ms |
574360 KB |
Output is correct |
4 |
Correct |
283 ms |
574036 KB |
Output is correct |
5 |
Correct |
284 ms |
573524 KB |
Output is correct |
6 |
Correct |
352 ms |
573880 KB |
Output is correct |
7 |
Correct |
340 ms |
573932 KB |
Output is correct |
8 |
Correct |
285 ms |
573524 KB |
Output is correct |
9 |
Correct |
227 ms |
573680 KB |
Output is correct |
10 |
Correct |
291 ms |
573544 KB |
Output is correct |
11 |
Correct |
347 ms |
573928 KB |
Output is correct |
12 |
Correct |
526 ms |
573936 KB |
Output is correct |
13 |
Correct |
445 ms |
573932 KB |
Output is correct |
14 |
Correct |
50 ms |
383124 KB |
Output is correct |
15 |
Correct |
337 ms |
574080 KB |
Output is correct |
16 |
Correct |
338 ms |
574292 KB |
Output is correct |
17 |
Correct |
350 ms |
573760 KB |
Output is correct |
18 |
Correct |
370 ms |
574032 KB |
Output is correct |
19 |
Correct |
345 ms |
573936 KB |
Output is correct |
20 |
Correct |
403 ms |
573816 KB |
Output is correct |
21 |
Correct |
380 ms |
573796 KB |
Output is correct |
22 |
Correct |
308 ms |
573712 KB |
Output is correct |
23 |
Correct |
349 ms |
573740 KB |
Output is correct |
24 |
Correct |
511 ms |
573924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
383060 KB |
Output is correct |
2 |
Correct |
337 ms |
574184 KB |
Output is correct |
3 |
Correct |
340 ms |
574360 KB |
Output is correct |
4 |
Correct |
283 ms |
574036 KB |
Output is correct |
5 |
Correct |
284 ms |
573524 KB |
Output is correct |
6 |
Correct |
352 ms |
573880 KB |
Output is correct |
7 |
Correct |
340 ms |
573932 KB |
Output is correct |
8 |
Correct |
285 ms |
573524 KB |
Output is correct |
9 |
Correct |
227 ms |
573680 KB |
Output is correct |
10 |
Correct |
291 ms |
573544 KB |
Output is correct |
11 |
Correct |
347 ms |
573928 KB |
Output is correct |
12 |
Correct |
526 ms |
573936 KB |
Output is correct |
13 |
Correct |
445 ms |
573932 KB |
Output is correct |
14 |
Correct |
50 ms |
383124 KB |
Output is correct |
15 |
Correct |
337 ms |
574080 KB |
Output is correct |
16 |
Correct |
338 ms |
574292 KB |
Output is correct |
17 |
Correct |
350 ms |
573760 KB |
Output is correct |
18 |
Correct |
370 ms |
574032 KB |
Output is correct |
19 |
Correct |
345 ms |
573936 KB |
Output is correct |
20 |
Correct |
403 ms |
573816 KB |
Output is correct |
21 |
Correct |
380 ms |
573796 KB |
Output is correct |
22 |
Correct |
308 ms |
573712 KB |
Output is correct |
23 |
Correct |
349 ms |
573740 KB |
Output is correct |
24 |
Correct |
511 ms |
573924 KB |
Output is correct |
25 |
Correct |
302 ms |
573248 KB |
Output is correct |
26 |
Correct |
344 ms |
574264 KB |
Output is correct |
27 |
Correct |
328 ms |
574024 KB |
Output is correct |
28 |
Correct |
329 ms |
573760 KB |
Output is correct |
29 |
Correct |
352 ms |
574036 KB |
Output is correct |
30 |
Correct |
404 ms |
573852 KB |
Output is correct |
31 |
Correct |
407 ms |
573780 KB |
Output is correct |
32 |
Correct |
478 ms |
573804 KB |
Output is correct |
33 |
Correct |
1012 ms |
573908 KB |
Output is correct |
34 |
Correct |
1193 ms |
573808 KB |
Output is correct |
35 |
Correct |
563 ms |
574032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
383060 KB |
Output is correct |
2 |
Correct |
3429 ms |
1895612 KB |
Output is correct |
3 |
Correct |
3368 ms |
1898860 KB |
Output is correct |
4 |
Correct |
3493 ms |
1898420 KB |
Output is correct |
5 |
Correct |
2740 ms |
1898056 KB |
Output is correct |
6 |
Correct |
3181 ms |
1902440 KB |
Output is correct |
7 |
Correct |
3161 ms |
1900624 KB |
Output is correct |
8 |
Correct |
45 ms |
383060 KB |
Output is correct |
9 |
Correct |
337 ms |
574184 KB |
Output is correct |
10 |
Correct |
340 ms |
574360 KB |
Output is correct |
11 |
Correct |
283 ms |
574036 KB |
Output is correct |
12 |
Correct |
284 ms |
573524 KB |
Output is correct |
13 |
Correct |
352 ms |
573880 KB |
Output is correct |
14 |
Correct |
340 ms |
573932 KB |
Output is correct |
15 |
Correct |
285 ms |
573524 KB |
Output is correct |
16 |
Correct |
227 ms |
573680 KB |
Output is correct |
17 |
Correct |
291 ms |
573544 KB |
Output is correct |
18 |
Correct |
347 ms |
573928 KB |
Output is correct |
19 |
Correct |
526 ms |
573936 KB |
Output is correct |
20 |
Correct |
445 ms |
573932 KB |
Output is correct |
21 |
Correct |
50 ms |
383124 KB |
Output is correct |
22 |
Correct |
337 ms |
574080 KB |
Output is correct |
23 |
Correct |
338 ms |
574292 KB |
Output is correct |
24 |
Correct |
350 ms |
573760 KB |
Output is correct |
25 |
Correct |
370 ms |
574032 KB |
Output is correct |
26 |
Correct |
345 ms |
573936 KB |
Output is correct |
27 |
Correct |
403 ms |
573816 KB |
Output is correct |
28 |
Correct |
380 ms |
573796 KB |
Output is correct |
29 |
Correct |
308 ms |
573712 KB |
Output is correct |
30 |
Correct |
349 ms |
573740 KB |
Output is correct |
31 |
Correct |
511 ms |
573924 KB |
Output is correct |
32 |
Correct |
302 ms |
573248 KB |
Output is correct |
33 |
Correct |
344 ms |
574264 KB |
Output is correct |
34 |
Correct |
328 ms |
574024 KB |
Output is correct |
35 |
Correct |
329 ms |
573760 KB |
Output is correct |
36 |
Correct |
352 ms |
574036 KB |
Output is correct |
37 |
Correct |
404 ms |
573852 KB |
Output is correct |
38 |
Correct |
407 ms |
573780 KB |
Output is correct |
39 |
Correct |
478 ms |
573804 KB |
Output is correct |
40 |
Correct |
1012 ms |
573908 KB |
Output is correct |
41 |
Correct |
1193 ms |
573808 KB |
Output is correct |
42 |
Correct |
563 ms |
574032 KB |
Output is correct |
43 |
Correct |
43 ms |
380948 KB |
Output is correct |
44 |
Correct |
46 ms |
383132 KB |
Output is correct |
45 |
Correct |
3169 ms |
1895548 KB |
Output is correct |
46 |
Correct |
3127 ms |
1897300 KB |
Output is correct |
47 |
Correct |
3197 ms |
1902892 KB |
Output is correct |
48 |
Correct |
2621 ms |
1903628 KB |
Output is correct |
49 |
Correct |
3246 ms |
1903392 KB |
Output is correct |
50 |
Correct |
3204 ms |
1903792 KB |
Output is correct |
51 |
Correct |
2566 ms |
1900196 KB |
Output is correct |
52 |
Correct |
3205 ms |
1902140 KB |
Output is correct |
53 |
Correct |
5188 ms |
1903696 KB |
Output is correct |
54 |
Correct |
4186 ms |
1904748 KB |
Output is correct |
55 |
Correct |
4286 ms |
1903724 KB |
Output is correct |
56 |
Correct |
5164 ms |
1904572 KB |
Output is correct |
57 |
Correct |
5378 ms |
1904408 KB |
Output is correct |
58 |
Correct |
5486 ms |
1904496 KB |
Output is correct |
59 |
Correct |
5717 ms |
1904624 KB |
Output is correct |
60 |
Correct |
4711 ms |
1903656 KB |
Output is correct |
61 |
Correct |
4367 ms |
1903852 KB |
Output is correct |