#include "dungeons.h"
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
const int N = 4e5 + 10 , Lg = 20;
const long long inf = 1e15 + 10;
int n;
vector <int> s , p , w , l;
long long f(long long x)
{
if(x <= 0)
return inf;
return x;
}
struct item{
long long mn;
long long val;
int id;
};
item a[2 * N][Lg];
item Get(item now , int len)
{
if(len == 0)
return now;
long long id = now.id , mn = now.mn , val = now.val , dif = val - (val >= s[id]) * s[id];
for(int i = Lg - 1 ; i >= 0 ; i--) if((1 << i) <= len && a[id * 2 + (val >= s[id])][i].mn > dif)
{
item tmp = a[id * 2 + (val >= s[id])][i];
return Get({min(mn , tmp.mn - dif) , tmp.val + dif , tmp.id} , len - (1 << i));
}
if(val >= s[id])
return Get({min(mn , f(s[w[id]] - val - s[id])) , val + s[id] , w[id]} , len - 1);
else
return Get({min(mn , f(s[l[id]] - val - p[id])) , val + p[id] , l[id]} , len - 1);
}
void init(int nn, vector<int> ss, vector<int> pp, vector<int> ww, vector<int> ll) {
n = nn;
s = ss;
p = pp;
w = ww;
l = ll;
s.push_back(0);
p.push_back(0);
w.push_back(n);
l.push_back(n);
for(int i = 0 ; i <= n ; i++)
{
a[i << 1][0] = {f(s[l[i]] - p[i]) , p[i] , l[i]};
a[(i << 1) + 1][0] = {f(s[w[i]] - 2 * s[i]) , 2 * s[i] , w[i]};
}
for(int j = 1 ; j < Lg ; j++) for(int i = 0 ; i <= 2 * n + 1 ; i++)
{
a[i][j] = Get(a[i][j - 1] , (1 << (j - 1)));
}
}
long long simulate(int x, int z) {
item tmp = Get({inf , z , x} , 2e7);
return tmp.val;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
2652 KB |
Output is correct |
4 |
Correct |
61 ms |
49996 KB |
Output is correct |
5 |
Correct |
3 ms |
2652 KB |
Output is correct |
6 |
Correct |
85 ms |
50160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
4949 ms |
399880 KB |
Output is correct |
3 |
Correct |
5530 ms |
397784 KB |
Output is correct |
4 |
Correct |
4796 ms |
398628 KB |
Output is correct |
5 |
Correct |
836 ms |
397024 KB |
Output is correct |
6 |
Correct |
4894 ms |
399564 KB |
Output is correct |
7 |
Correct |
3006 ms |
399840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2648 KB |
Output is correct |
2 |
Correct |
96 ms |
50764 KB |
Output is correct |
3 |
Correct |
103 ms |
50948 KB |
Output is correct |
4 |
Correct |
98 ms |
50764 KB |
Output is correct |
5 |
Correct |
98 ms |
50760 KB |
Output is correct |
6 |
Correct |
123 ms |
50908 KB |
Output is correct |
7 |
Correct |
115 ms |
50760 KB |
Output is correct |
8 |
Correct |
96 ms |
50764 KB |
Output is correct |
9 |
Correct |
103 ms |
50764 KB |
Output is correct |
10 |
Correct |
99 ms |
50764 KB |
Output is correct |
11 |
Correct |
110 ms |
50764 KB |
Output is correct |
12 |
Correct |
210 ms |
50688 KB |
Output is correct |
13 |
Correct |
167 ms |
50764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2648 KB |
Output is correct |
2 |
Correct |
96 ms |
50764 KB |
Output is correct |
3 |
Correct |
103 ms |
50948 KB |
Output is correct |
4 |
Correct |
98 ms |
50764 KB |
Output is correct |
5 |
Correct |
98 ms |
50760 KB |
Output is correct |
6 |
Correct |
123 ms |
50908 KB |
Output is correct |
7 |
Correct |
115 ms |
50760 KB |
Output is correct |
8 |
Correct |
96 ms |
50764 KB |
Output is correct |
9 |
Correct |
103 ms |
50764 KB |
Output is correct |
10 |
Correct |
99 ms |
50764 KB |
Output is correct |
11 |
Correct |
110 ms |
50764 KB |
Output is correct |
12 |
Correct |
210 ms |
50688 KB |
Output is correct |
13 |
Correct |
167 ms |
50764 KB |
Output is correct |
14 |
Correct |
3 ms |
2652 KB |
Output is correct |
15 |
Correct |
162 ms |
50908 KB |
Output is correct |
16 |
Correct |
110 ms |
50948 KB |
Output is correct |
17 |
Correct |
112 ms |
50760 KB |
Output is correct |
18 |
Correct |
155 ms |
50760 KB |
Output is correct |
19 |
Correct |
127 ms |
50904 KB |
Output is correct |
20 |
Correct |
285 ms |
50764 KB |
Output is correct |
21 |
Correct |
217 ms |
50760 KB |
Output is correct |
22 |
Correct |
170 ms |
50764 KB |
Output is correct |
23 |
Correct |
108 ms |
50944 KB |
Output is correct |
24 |
Correct |
164 ms |
50764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2648 KB |
Output is correct |
2 |
Correct |
96 ms |
50764 KB |
Output is correct |
3 |
Correct |
103 ms |
50948 KB |
Output is correct |
4 |
Correct |
98 ms |
50764 KB |
Output is correct |
5 |
Correct |
98 ms |
50760 KB |
Output is correct |
6 |
Correct |
123 ms |
50908 KB |
Output is correct |
7 |
Correct |
115 ms |
50760 KB |
Output is correct |
8 |
Correct |
96 ms |
50764 KB |
Output is correct |
9 |
Correct |
103 ms |
50764 KB |
Output is correct |
10 |
Correct |
99 ms |
50764 KB |
Output is correct |
11 |
Correct |
110 ms |
50764 KB |
Output is correct |
12 |
Correct |
210 ms |
50688 KB |
Output is correct |
13 |
Correct |
167 ms |
50764 KB |
Output is correct |
14 |
Correct |
3 ms |
2652 KB |
Output is correct |
15 |
Correct |
162 ms |
50908 KB |
Output is correct |
16 |
Correct |
110 ms |
50948 KB |
Output is correct |
17 |
Correct |
112 ms |
50760 KB |
Output is correct |
18 |
Correct |
155 ms |
50760 KB |
Output is correct |
19 |
Correct |
127 ms |
50904 KB |
Output is correct |
20 |
Correct |
285 ms |
50764 KB |
Output is correct |
21 |
Correct |
217 ms |
50760 KB |
Output is correct |
22 |
Correct |
170 ms |
50764 KB |
Output is correct |
23 |
Correct |
108 ms |
50944 KB |
Output is correct |
24 |
Correct |
164 ms |
50764 KB |
Output is correct |
25 |
Correct |
63 ms |
50180 KB |
Output is correct |
26 |
Correct |
110 ms |
50760 KB |
Output is correct |
27 |
Correct |
276 ms |
50944 KB |
Output is correct |
28 |
Correct |
215 ms |
50944 KB |
Output is correct |
29 |
Correct |
104 ms |
50760 KB |
Output is correct |
30 |
Correct |
344 ms |
51196 KB |
Output is correct |
31 |
Correct |
485 ms |
50952 KB |
Output is correct |
32 |
Correct |
497 ms |
50900 KB |
Output is correct |
33 |
Correct |
161 ms |
50764 KB |
Output is correct |
34 |
Correct |
188 ms |
50764 KB |
Output is correct |
35 |
Correct |
369 ms |
50756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
4949 ms |
399880 KB |
Output is correct |
3 |
Correct |
5530 ms |
397784 KB |
Output is correct |
4 |
Correct |
4796 ms |
398628 KB |
Output is correct |
5 |
Correct |
836 ms |
397024 KB |
Output is correct |
6 |
Correct |
4894 ms |
399564 KB |
Output is correct |
7 |
Correct |
3006 ms |
399840 KB |
Output is correct |
8 |
Correct |
4 ms |
2648 KB |
Output is correct |
9 |
Correct |
96 ms |
50764 KB |
Output is correct |
10 |
Correct |
103 ms |
50948 KB |
Output is correct |
11 |
Correct |
98 ms |
50764 KB |
Output is correct |
12 |
Correct |
98 ms |
50760 KB |
Output is correct |
13 |
Correct |
123 ms |
50908 KB |
Output is correct |
14 |
Correct |
115 ms |
50760 KB |
Output is correct |
15 |
Correct |
96 ms |
50764 KB |
Output is correct |
16 |
Correct |
103 ms |
50764 KB |
Output is correct |
17 |
Correct |
99 ms |
50764 KB |
Output is correct |
18 |
Correct |
110 ms |
50764 KB |
Output is correct |
19 |
Correct |
210 ms |
50688 KB |
Output is correct |
20 |
Correct |
167 ms |
50764 KB |
Output is correct |
21 |
Correct |
3 ms |
2652 KB |
Output is correct |
22 |
Correct |
162 ms |
50908 KB |
Output is correct |
23 |
Correct |
110 ms |
50948 KB |
Output is correct |
24 |
Correct |
112 ms |
50760 KB |
Output is correct |
25 |
Correct |
155 ms |
50760 KB |
Output is correct |
26 |
Correct |
127 ms |
50904 KB |
Output is correct |
27 |
Correct |
285 ms |
50764 KB |
Output is correct |
28 |
Correct |
217 ms |
50760 KB |
Output is correct |
29 |
Correct |
170 ms |
50764 KB |
Output is correct |
30 |
Correct |
108 ms |
50944 KB |
Output is correct |
31 |
Correct |
164 ms |
50764 KB |
Output is correct |
32 |
Correct |
63 ms |
50180 KB |
Output is correct |
33 |
Correct |
110 ms |
50760 KB |
Output is correct |
34 |
Correct |
276 ms |
50944 KB |
Output is correct |
35 |
Correct |
215 ms |
50944 KB |
Output is correct |
36 |
Correct |
104 ms |
50760 KB |
Output is correct |
37 |
Correct |
344 ms |
51196 KB |
Output is correct |
38 |
Correct |
485 ms |
50952 KB |
Output is correct |
39 |
Correct |
497 ms |
50900 KB |
Output is correct |
40 |
Correct |
161 ms |
50764 KB |
Output is correct |
41 |
Correct |
188 ms |
50764 KB |
Output is correct |
42 |
Correct |
369 ms |
50756 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
2 ms |
2652 KB |
Output is correct |
45 |
Correct |
825 ms |
399304 KB |
Output is correct |
46 |
Correct |
2907 ms |
397788 KB |
Output is correct |
47 |
Correct |
2017 ms |
398704 KB |
Output is correct |
48 |
Correct |
3618 ms |
397008 KB |
Output is correct |
49 |
Correct |
820 ms |
397772 KB |
Output is correct |
50 |
Correct |
4647 ms |
398816 KB |
Output is correct |
51 |
Correct |
978 ms |
396748 KB |
Output is correct |
52 |
Correct |
4936 ms |
399312 KB |
Output is correct |
53 |
Execution timed out |
7070 ms |
396988 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |