#include "dungeons.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
const int k = 20;
vector<vector<long long>>table;
vector<vector<long long>>nx;
vector<vector<long long>>bk;
vector<vector<long long>>sum;
vector<vector<long long>>bksum;
vector<vector<long long>>need;
vector<int>S,P,W,L;
long long N;
void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) {
table.resize(n,vector<long long>(k));
nx.resize(n,vector<long long>(k,-1));
sum.resize(n,vector<long long>(k,0));
need.resize(n,vector<long long>(k,1e16));
bk.resize(n,vector<long long>(k,-1));
bksum.resize(n,vector<long long>(k,0));
N = n;
S = s;
P = p;
W = w;
L = l;
for (long long i = 0;i<n;++i){
table[i][0] = s[i];
nx[i][0] = w[i];
sum[i][0] = s[i];
need[i][0] = s[i];
bk[i][0] = l[i];
bksum[i][0] = p[i];
}
for (long long i = 1;i<k;++i){
for (long long j = 0;j<n;++j){
if (nx[j][i - 1] == -1 || nx[j][i - 1] == n)continue;
//cout<<nx[j][i - 1]<<'\n';
nx[j][i] = nx[nx[j][i - 1]][i - 1];
table[j][i] = max(table[j][i - 1],table[nx[j][i - 1]][i - 1] - sum[j][i - 1]);
sum[j][i] = sum[j][i - 1] + sum[nx[j][i - 1]][i - 1];
}
}
for (long long i = 1;i<k;++i){
for (long long j = 0;j<n;++j){
if (bk[j][i - 1] == -1 || bk[j][i - 1] == n)continue;
//cout<<nx[j][i - 1]<<'\n';
bk[j][i] = bk[bk[j][i - 1]][i - 1];
need[j][i] = min(need[j][i - 1],need[bk[j][i - 1]][i - 1] - bksum[j][i - 1]);
bksum[j][i] = bksum[j][i - 1] + bksum[bk[j][i - 1]][i - 1];
}
}
return;
}
long long simulate(int x, int z) {
unordered_map<int,long long>mp;
long long Z = z;
int cnt = 0;
while(x != N){
if (mp.find(x) != mp.end() && S[x] > Z){
long long v = Z - mp[x];
long long k = (S[x] - Z + v - 1) / v;
Z+=k * v;
}
mp[x] = Z;
cnt++;
//assert(cnt < 50);
// cout<<x<<"->";
long long c = -1;
int left = 0,right = k - 1;
while(left <= right){
int mid = (left + right)>>1;
if (nx[x][mid] != -1 && table[x][mid] <= Z){
left = mid + 1;
c = mid;
}
else right = mid - 1;
}
++c;
//while(nx[x][c] != -1 && table[x][c] <= Z){
// ++c;
//}
if (c != 0){
Z+=sum[x][c - 1];
x = nx[x][c - 1];
}
if (x != N && S[x] > Z){
int cc = 0;
while(bk[x][cc]!=-1 && need[x][cc] > Z){
++cc;
}
cc--;
while(cc >= 0 && x != N){
// cout<<x<<"->";
if (bk[x][cc] != -1){
if (need[x][cc] <= Z){
cc--;
}
else{
Z+=bksum[x][cc];
x = bk[x][cc];
}
}
else cc--;
}
//cout<<'\n';
}
}
// cout<<'\n';
return Z;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
2652 KB |
Output is correct |
4 |
Correct |
62 ms |
61484 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
67 ms |
61480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1628 KB |
Output is correct |
2 |
Correct |
698 ms |
489676 KB |
Output is correct |
3 |
Correct |
711 ms |
489684 KB |
Output is correct |
4 |
Correct |
696 ms |
489544 KB |
Output is correct |
5 |
Correct |
605 ms |
489684 KB |
Output is correct |
6 |
Correct |
736 ms |
489552 KB |
Output is correct |
7 |
Correct |
916 ms |
489780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1624 KB |
Output is correct |
2 |
Correct |
96 ms |
62272 KB |
Output is correct |
3 |
Correct |
120 ms |
62168 KB |
Output is correct |
4 |
Correct |
134 ms |
62032 KB |
Output is correct |
5 |
Correct |
104 ms |
62040 KB |
Output is correct |
6 |
Correct |
109 ms |
62152 KB |
Output is correct |
7 |
Correct |
108 ms |
62036 KB |
Output is correct |
8 |
Correct |
110 ms |
62040 KB |
Output is correct |
9 |
Correct |
95 ms |
62044 KB |
Output is correct |
10 |
Correct |
119 ms |
62268 KB |
Output is correct |
11 |
Correct |
107 ms |
62072 KB |
Output is correct |
12 |
Correct |
207 ms |
62032 KB |
Output is correct |
13 |
Correct |
194 ms |
62036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1624 KB |
Output is correct |
2 |
Correct |
96 ms |
62272 KB |
Output is correct |
3 |
Correct |
120 ms |
62168 KB |
Output is correct |
4 |
Correct |
134 ms |
62032 KB |
Output is correct |
5 |
Correct |
104 ms |
62040 KB |
Output is correct |
6 |
Correct |
109 ms |
62152 KB |
Output is correct |
7 |
Correct |
108 ms |
62036 KB |
Output is correct |
8 |
Correct |
110 ms |
62040 KB |
Output is correct |
9 |
Correct |
95 ms |
62044 KB |
Output is correct |
10 |
Correct |
119 ms |
62268 KB |
Output is correct |
11 |
Correct |
107 ms |
62072 KB |
Output is correct |
12 |
Correct |
207 ms |
62032 KB |
Output is correct |
13 |
Correct |
194 ms |
62036 KB |
Output is correct |
14 |
Correct |
2 ms |
1628 KB |
Output is correct |
15 |
Correct |
180 ms |
62272 KB |
Output is correct |
16 |
Correct |
100 ms |
62036 KB |
Output is correct |
17 |
Correct |
108 ms |
62036 KB |
Output is correct |
18 |
Correct |
111 ms |
62244 KB |
Output is correct |
19 |
Correct |
118 ms |
62276 KB |
Output is correct |
20 |
Correct |
118 ms |
62036 KB |
Output is correct |
21 |
Correct |
118 ms |
62168 KB |
Output is correct |
22 |
Execution timed out |
7036 ms |
62040 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1624 KB |
Output is correct |
2 |
Correct |
96 ms |
62272 KB |
Output is correct |
3 |
Correct |
120 ms |
62168 KB |
Output is correct |
4 |
Correct |
134 ms |
62032 KB |
Output is correct |
5 |
Correct |
104 ms |
62040 KB |
Output is correct |
6 |
Correct |
109 ms |
62152 KB |
Output is correct |
7 |
Correct |
108 ms |
62036 KB |
Output is correct |
8 |
Correct |
110 ms |
62040 KB |
Output is correct |
9 |
Correct |
95 ms |
62044 KB |
Output is correct |
10 |
Correct |
119 ms |
62268 KB |
Output is correct |
11 |
Correct |
107 ms |
62072 KB |
Output is correct |
12 |
Correct |
207 ms |
62032 KB |
Output is correct |
13 |
Correct |
194 ms |
62036 KB |
Output is correct |
14 |
Correct |
2 ms |
1628 KB |
Output is correct |
15 |
Correct |
180 ms |
62272 KB |
Output is correct |
16 |
Correct |
100 ms |
62036 KB |
Output is correct |
17 |
Correct |
108 ms |
62036 KB |
Output is correct |
18 |
Correct |
111 ms |
62244 KB |
Output is correct |
19 |
Correct |
118 ms |
62276 KB |
Output is correct |
20 |
Correct |
118 ms |
62036 KB |
Output is correct |
21 |
Correct |
118 ms |
62168 KB |
Output is correct |
22 |
Execution timed out |
7036 ms |
62040 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1628 KB |
Output is correct |
2 |
Correct |
698 ms |
489676 KB |
Output is correct |
3 |
Correct |
711 ms |
489684 KB |
Output is correct |
4 |
Correct |
696 ms |
489544 KB |
Output is correct |
5 |
Correct |
605 ms |
489684 KB |
Output is correct |
6 |
Correct |
736 ms |
489552 KB |
Output is correct |
7 |
Correct |
916 ms |
489780 KB |
Output is correct |
8 |
Correct |
2 ms |
1624 KB |
Output is correct |
9 |
Correct |
96 ms |
62272 KB |
Output is correct |
10 |
Correct |
120 ms |
62168 KB |
Output is correct |
11 |
Correct |
134 ms |
62032 KB |
Output is correct |
12 |
Correct |
104 ms |
62040 KB |
Output is correct |
13 |
Correct |
109 ms |
62152 KB |
Output is correct |
14 |
Correct |
108 ms |
62036 KB |
Output is correct |
15 |
Correct |
110 ms |
62040 KB |
Output is correct |
16 |
Correct |
95 ms |
62044 KB |
Output is correct |
17 |
Correct |
119 ms |
62268 KB |
Output is correct |
18 |
Correct |
107 ms |
62072 KB |
Output is correct |
19 |
Correct |
207 ms |
62032 KB |
Output is correct |
20 |
Correct |
194 ms |
62036 KB |
Output is correct |
21 |
Correct |
2 ms |
1628 KB |
Output is correct |
22 |
Correct |
180 ms |
62272 KB |
Output is correct |
23 |
Correct |
100 ms |
62036 KB |
Output is correct |
24 |
Correct |
108 ms |
62036 KB |
Output is correct |
25 |
Correct |
111 ms |
62244 KB |
Output is correct |
26 |
Correct |
118 ms |
62276 KB |
Output is correct |
27 |
Correct |
118 ms |
62036 KB |
Output is correct |
28 |
Correct |
118 ms |
62168 KB |
Output is correct |
29 |
Execution timed out |
7036 ms |
62040 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |