#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];
inline item Get(item now , int len)
{
while(len != 0)
{
long long id = now.id , mn = now.mn , val = now.val , dif = val - (val >= s[id]) * s[id];
bool flg = false;
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];
now = {min(mn , tmp.mn - dif) , tmp.val + dif , tmp.id};
len = len - (1 << i);
flg = true;
break;
}
}
return now;
}
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] = {s[i] , p[i] , l[i]};
a[(i << 1) + 1][0] = {inf , 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;
}
Compilation message
dungeons.cpp: In function 'item Get(item, int)':
dungeons.cpp:34:8: warning: variable 'flg' set but not used [-Wunused-but-set-variable]
34 | bool flg = false;
| ^~~
# |
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 |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
36 ms |
50116 KB |
Output is correct |
5 |
Correct |
3 ms |
2652 KB |
Output is correct |
6 |
Correct |
50 ms |
50116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Correct |
3769 ms |
396948 KB |
Output is correct |
3 |
Correct |
4204 ms |
398048 KB |
Output is correct |
4 |
Correct |
3697 ms |
396764 KB |
Output is correct |
5 |
Correct |
538 ms |
398560 KB |
Output is correct |
6 |
Correct |
3559 ms |
399028 KB |
Output is correct |
7 |
Correct |
1917 ms |
397696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
57 ms |
50760 KB |
Output is correct |
3 |
Correct |
60 ms |
50764 KB |
Output is correct |
4 |
Correct |
58 ms |
50760 KB |
Output is correct |
5 |
Correct |
56 ms |
50764 KB |
Output is correct |
6 |
Correct |
72 ms |
50764 KB |
Output is correct |
7 |
Correct |
67 ms |
50764 KB |
Output is correct |
8 |
Correct |
58 ms |
50764 KB |
Output is correct |
9 |
Correct |
57 ms |
50764 KB |
Output is correct |
10 |
Correct |
59 ms |
50764 KB |
Output is correct |
11 |
Correct |
62 ms |
51008 KB |
Output is correct |
12 |
Correct |
115 ms |
50764 KB |
Output is correct |
13 |
Correct |
109 ms |
50760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
57 ms |
50760 KB |
Output is correct |
3 |
Correct |
60 ms |
50764 KB |
Output is correct |
4 |
Correct |
58 ms |
50760 KB |
Output is correct |
5 |
Correct |
56 ms |
50764 KB |
Output is correct |
6 |
Correct |
72 ms |
50764 KB |
Output is correct |
7 |
Correct |
67 ms |
50764 KB |
Output is correct |
8 |
Correct |
58 ms |
50764 KB |
Output is correct |
9 |
Correct |
57 ms |
50764 KB |
Output is correct |
10 |
Correct |
59 ms |
50764 KB |
Output is correct |
11 |
Correct |
62 ms |
51008 KB |
Output is correct |
12 |
Correct |
115 ms |
50764 KB |
Output is correct |
13 |
Correct |
109 ms |
50760 KB |
Output is correct |
14 |
Correct |
2 ms |
2652 KB |
Output is correct |
15 |
Correct |
97 ms |
50912 KB |
Output is correct |
16 |
Correct |
62 ms |
50764 KB |
Output is correct |
17 |
Correct |
64 ms |
50944 KB |
Output is correct |
18 |
Correct |
78 ms |
50760 KB |
Output is correct |
19 |
Correct |
72 ms |
50912 KB |
Output is correct |
20 |
Correct |
167 ms |
50764 KB |
Output is correct |
21 |
Correct |
127 ms |
50764 KB |
Output is correct |
22 |
Correct |
102 ms |
50944 KB |
Output is correct |
23 |
Correct |
61 ms |
50764 KB |
Output is correct |
24 |
Correct |
102 ms |
50764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
57 ms |
50760 KB |
Output is correct |
3 |
Correct |
60 ms |
50764 KB |
Output is correct |
4 |
Correct |
58 ms |
50760 KB |
Output is correct |
5 |
Correct |
56 ms |
50764 KB |
Output is correct |
6 |
Correct |
72 ms |
50764 KB |
Output is correct |
7 |
Correct |
67 ms |
50764 KB |
Output is correct |
8 |
Correct |
58 ms |
50764 KB |
Output is correct |
9 |
Correct |
57 ms |
50764 KB |
Output is correct |
10 |
Correct |
59 ms |
50764 KB |
Output is correct |
11 |
Correct |
62 ms |
51008 KB |
Output is correct |
12 |
Correct |
115 ms |
50764 KB |
Output is correct |
13 |
Correct |
109 ms |
50760 KB |
Output is correct |
14 |
Correct |
2 ms |
2652 KB |
Output is correct |
15 |
Correct |
97 ms |
50912 KB |
Output is correct |
16 |
Correct |
62 ms |
50764 KB |
Output is correct |
17 |
Correct |
64 ms |
50944 KB |
Output is correct |
18 |
Correct |
78 ms |
50760 KB |
Output is correct |
19 |
Correct |
72 ms |
50912 KB |
Output is correct |
20 |
Correct |
167 ms |
50764 KB |
Output is correct |
21 |
Correct |
127 ms |
50764 KB |
Output is correct |
22 |
Correct |
102 ms |
50944 KB |
Output is correct |
23 |
Correct |
61 ms |
50764 KB |
Output is correct |
24 |
Correct |
102 ms |
50764 KB |
Output is correct |
25 |
Correct |
38 ms |
50248 KB |
Output is correct |
26 |
Correct |
63 ms |
50760 KB |
Output is correct |
27 |
Correct |
146 ms |
50764 KB |
Output is correct |
28 |
Correct |
122 ms |
50764 KB |
Output is correct |
29 |
Correct |
78 ms |
50760 KB |
Output is correct |
30 |
Correct |
212 ms |
50764 KB |
Output is correct |
31 |
Correct |
320 ms |
50764 KB |
Output is correct |
32 |
Correct |
322 ms |
50944 KB |
Output is correct |
33 |
Correct |
103 ms |
50764 KB |
Output is correct |
34 |
Correct |
99 ms |
50944 KB |
Output is correct |
35 |
Correct |
205 ms |
50940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Correct |
3769 ms |
396948 KB |
Output is correct |
3 |
Correct |
4204 ms |
398048 KB |
Output is correct |
4 |
Correct |
3697 ms |
396764 KB |
Output is correct |
5 |
Correct |
538 ms |
398560 KB |
Output is correct |
6 |
Correct |
3559 ms |
399028 KB |
Output is correct |
7 |
Correct |
1917 ms |
397696 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
57 ms |
50760 KB |
Output is correct |
10 |
Correct |
60 ms |
50764 KB |
Output is correct |
11 |
Correct |
58 ms |
50760 KB |
Output is correct |
12 |
Correct |
56 ms |
50764 KB |
Output is correct |
13 |
Correct |
72 ms |
50764 KB |
Output is correct |
14 |
Correct |
67 ms |
50764 KB |
Output is correct |
15 |
Correct |
58 ms |
50764 KB |
Output is correct |
16 |
Correct |
57 ms |
50764 KB |
Output is correct |
17 |
Correct |
59 ms |
50764 KB |
Output is correct |
18 |
Correct |
62 ms |
51008 KB |
Output is correct |
19 |
Correct |
115 ms |
50764 KB |
Output is correct |
20 |
Correct |
109 ms |
50760 KB |
Output is correct |
21 |
Correct |
2 ms |
2652 KB |
Output is correct |
22 |
Correct |
97 ms |
50912 KB |
Output is correct |
23 |
Correct |
62 ms |
50764 KB |
Output is correct |
24 |
Correct |
64 ms |
50944 KB |
Output is correct |
25 |
Correct |
78 ms |
50760 KB |
Output is correct |
26 |
Correct |
72 ms |
50912 KB |
Output is correct |
27 |
Correct |
167 ms |
50764 KB |
Output is correct |
28 |
Correct |
127 ms |
50764 KB |
Output is correct |
29 |
Correct |
102 ms |
50944 KB |
Output is correct |
30 |
Correct |
61 ms |
50764 KB |
Output is correct |
31 |
Correct |
102 ms |
50764 KB |
Output is correct |
32 |
Correct |
38 ms |
50248 KB |
Output is correct |
33 |
Correct |
63 ms |
50760 KB |
Output is correct |
34 |
Correct |
146 ms |
50764 KB |
Output is correct |
35 |
Correct |
122 ms |
50764 KB |
Output is correct |
36 |
Correct |
78 ms |
50760 KB |
Output is correct |
37 |
Correct |
212 ms |
50764 KB |
Output is correct |
38 |
Correct |
320 ms |
50764 KB |
Output is correct |
39 |
Correct |
322 ms |
50944 KB |
Output is correct |
40 |
Correct |
103 ms |
50764 KB |
Output is correct |
41 |
Correct |
99 ms |
50944 KB |
Output is correct |
42 |
Correct |
205 ms |
50940 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
1 ms |
2652 KB |
Output is correct |
45 |
Correct |
537 ms |
396764 KB |
Output is correct |
46 |
Correct |
1479 ms |
397840 KB |
Output is correct |
47 |
Correct |
1168 ms |
396960 KB |
Output is correct |
48 |
Correct |
2600 ms |
397196 KB |
Output is correct |
49 |
Correct |
647 ms |
397028 KB |
Output is correct |
50 |
Correct |
3463 ms |
397784 KB |
Output is correct |
51 |
Correct |
668 ms |
397508 KB |
Output is correct |
52 |
Correct |
3519 ms |
397064 KB |
Output is correct |
53 |
Correct |
6849 ms |
396624 KB |
Output is correct |
54 |
Correct |
1461 ms |
407332 KB |
Output is correct |
55 |
Correct |
2318 ms |
405980 KB |
Output is correct |
56 |
Correct |
3214 ms |
405816 KB |
Output is correct |
57 |
Correct |
2931 ms |
405468 KB |
Output is correct |
58 |
Correct |
2661 ms |
407516 KB |
Output is correct |
59 |
Correct |
2564 ms |
406060 KB |
Output is correct |
60 |
Correct |
5914 ms |
406004 KB |
Output is correct |
61 |
Correct |
5122 ms |
404884 KB |
Output is correct |