#include "dungeons.h"
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
const int N = 4e5 + 10 , Lg = 27;
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] = {min(s[i] * 1LL , 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 |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
4700 KB |
Output is correct |
4 |
Correct |
99 ms |
66988 KB |
Output is correct |
5 |
Correct |
6 ms |
4956 KB |
Output is correct |
6 |
Correct |
122 ms |
66848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
5451 ms |
532556 KB |
Output is correct |
3 |
Correct |
6281 ms |
533468 KB |
Output is correct |
4 |
Correct |
5270 ms |
534236 KB |
Output is correct |
5 |
Correct |
1081 ms |
535516 KB |
Output is correct |
6 |
Correct |
5568 ms |
530408 KB |
Output is correct |
7 |
Correct |
4356 ms |
530656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
103 ms |
66892 KB |
Output is correct |
3 |
Correct |
137 ms |
66980 KB |
Output is correct |
4 |
Correct |
119 ms |
66980 KB |
Output is correct |
5 |
Correct |
134 ms |
66976 KB |
Output is correct |
6 |
Correct |
157 ms |
66780 KB |
Output is correct |
7 |
Correct |
179 ms |
66892 KB |
Output is correct |
8 |
Correct |
135 ms |
66872 KB |
Output is correct |
9 |
Correct |
131 ms |
66976 KB |
Output is correct |
10 |
Correct |
136 ms |
66976 KB |
Output is correct |
11 |
Correct |
130 ms |
66972 KB |
Output is correct |
12 |
Correct |
324 ms |
66792 KB |
Output is correct |
13 |
Correct |
256 ms |
66980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
103 ms |
66892 KB |
Output is correct |
3 |
Correct |
137 ms |
66980 KB |
Output is correct |
4 |
Correct |
119 ms |
66980 KB |
Output is correct |
5 |
Correct |
134 ms |
66976 KB |
Output is correct |
6 |
Correct |
157 ms |
66780 KB |
Output is correct |
7 |
Correct |
179 ms |
66892 KB |
Output is correct |
8 |
Correct |
135 ms |
66872 KB |
Output is correct |
9 |
Correct |
131 ms |
66976 KB |
Output is correct |
10 |
Correct |
136 ms |
66976 KB |
Output is correct |
11 |
Correct |
130 ms |
66972 KB |
Output is correct |
12 |
Correct |
324 ms |
66792 KB |
Output is correct |
13 |
Correct |
256 ms |
66980 KB |
Output is correct |
14 |
Correct |
3 ms |
2748 KB |
Output is correct |
15 |
Correct |
227 ms |
66972 KB |
Output is correct |
16 |
Correct |
123 ms |
66892 KB |
Output is correct |
17 |
Correct |
173 ms |
66888 KB |
Output is correct |
18 |
Correct |
159 ms |
66976 KB |
Output is correct |
19 |
Correct |
196 ms |
66884 KB |
Output is correct |
20 |
Correct |
422 ms |
66780 KB |
Output is correct |
21 |
Correct |
283 ms |
66972 KB |
Output is correct |
22 |
Correct |
213 ms |
66892 KB |
Output is correct |
23 |
Correct |
132 ms |
66808 KB |
Output is correct |
24 |
Correct |
284 ms |
66892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
103 ms |
66892 KB |
Output is correct |
3 |
Correct |
137 ms |
66980 KB |
Output is correct |
4 |
Correct |
119 ms |
66980 KB |
Output is correct |
5 |
Correct |
134 ms |
66976 KB |
Output is correct |
6 |
Correct |
157 ms |
66780 KB |
Output is correct |
7 |
Correct |
179 ms |
66892 KB |
Output is correct |
8 |
Correct |
135 ms |
66872 KB |
Output is correct |
9 |
Correct |
131 ms |
66976 KB |
Output is correct |
10 |
Correct |
136 ms |
66976 KB |
Output is correct |
11 |
Correct |
130 ms |
66972 KB |
Output is correct |
12 |
Correct |
324 ms |
66792 KB |
Output is correct |
13 |
Correct |
256 ms |
66980 KB |
Output is correct |
14 |
Correct |
3 ms |
2748 KB |
Output is correct |
15 |
Correct |
227 ms |
66972 KB |
Output is correct |
16 |
Correct |
123 ms |
66892 KB |
Output is correct |
17 |
Correct |
173 ms |
66888 KB |
Output is correct |
18 |
Correct |
159 ms |
66976 KB |
Output is correct |
19 |
Correct |
196 ms |
66884 KB |
Output is correct |
20 |
Correct |
422 ms |
66780 KB |
Output is correct |
21 |
Correct |
283 ms |
66972 KB |
Output is correct |
22 |
Correct |
213 ms |
66892 KB |
Output is correct |
23 |
Correct |
132 ms |
66808 KB |
Output is correct |
24 |
Correct |
284 ms |
66892 KB |
Output is correct |
25 |
Correct |
103 ms |
66124 KB |
Output is correct |
26 |
Correct |
125 ms |
66888 KB |
Output is correct |
27 |
Correct |
390 ms |
66984 KB |
Output is correct |
28 |
Correct |
256 ms |
66888 KB |
Output is correct |
29 |
Correct |
116 ms |
66888 KB |
Output is correct |
30 |
Correct |
469 ms |
66888 KB |
Output is correct |
31 |
Correct |
737 ms |
66976 KB |
Output is correct |
32 |
Correct |
717 ms |
66976 KB |
Output is correct |
33 |
Correct |
291 ms |
66772 KB |
Output is correct |
34 |
Correct |
271 ms |
66952 KB |
Output is correct |
35 |
Correct |
474 ms |
66888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
5451 ms |
532556 KB |
Output is correct |
3 |
Correct |
6281 ms |
533468 KB |
Output is correct |
4 |
Correct |
5270 ms |
534236 KB |
Output is correct |
5 |
Correct |
1081 ms |
535516 KB |
Output is correct |
6 |
Correct |
5568 ms |
530408 KB |
Output is correct |
7 |
Correct |
4356 ms |
530656 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
103 ms |
66892 KB |
Output is correct |
10 |
Correct |
137 ms |
66980 KB |
Output is correct |
11 |
Correct |
119 ms |
66980 KB |
Output is correct |
12 |
Correct |
134 ms |
66976 KB |
Output is correct |
13 |
Correct |
157 ms |
66780 KB |
Output is correct |
14 |
Correct |
179 ms |
66892 KB |
Output is correct |
15 |
Correct |
135 ms |
66872 KB |
Output is correct |
16 |
Correct |
131 ms |
66976 KB |
Output is correct |
17 |
Correct |
136 ms |
66976 KB |
Output is correct |
18 |
Correct |
130 ms |
66972 KB |
Output is correct |
19 |
Correct |
324 ms |
66792 KB |
Output is correct |
20 |
Correct |
256 ms |
66980 KB |
Output is correct |
21 |
Correct |
3 ms |
2748 KB |
Output is correct |
22 |
Correct |
227 ms |
66972 KB |
Output is correct |
23 |
Correct |
123 ms |
66892 KB |
Output is correct |
24 |
Correct |
173 ms |
66888 KB |
Output is correct |
25 |
Correct |
159 ms |
66976 KB |
Output is correct |
26 |
Correct |
196 ms |
66884 KB |
Output is correct |
27 |
Correct |
422 ms |
66780 KB |
Output is correct |
28 |
Correct |
283 ms |
66972 KB |
Output is correct |
29 |
Correct |
213 ms |
66892 KB |
Output is correct |
30 |
Correct |
132 ms |
66808 KB |
Output is correct |
31 |
Correct |
284 ms |
66892 KB |
Output is correct |
32 |
Correct |
103 ms |
66124 KB |
Output is correct |
33 |
Correct |
125 ms |
66888 KB |
Output is correct |
34 |
Correct |
390 ms |
66984 KB |
Output is correct |
35 |
Correct |
256 ms |
66888 KB |
Output is correct |
36 |
Correct |
116 ms |
66888 KB |
Output is correct |
37 |
Correct |
469 ms |
66888 KB |
Output is correct |
38 |
Correct |
737 ms |
66976 KB |
Output is correct |
39 |
Correct |
717 ms |
66976 KB |
Output is correct |
40 |
Correct |
291 ms |
66772 KB |
Output is correct |
41 |
Correct |
271 ms |
66952 KB |
Output is correct |
42 |
Correct |
474 ms |
66888 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
2752 KB |
Output is correct |
45 |
Correct |
1249 ms |
527984 KB |
Output is correct |
46 |
Correct |
3748 ms |
530520 KB |
Output is correct |
47 |
Correct |
2522 ms |
529348 KB |
Output is correct |
48 |
Correct |
4520 ms |
528420 KB |
Output is correct |
49 |
Correct |
1144 ms |
539100 KB |
Output is correct |
50 |
Correct |
5280 ms |
537060 KB |
Output is correct |
51 |
Correct |
1240 ms |
537580 KB |
Output is correct |
52 |
Correct |
5432 ms |
537056 KB |
Output is correct |
53 |
Execution timed out |
7095 ms |
536268 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |