#include "dungeons.h"
#define pb push_back
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector <int> vec;
int n;
int s[400005],p[400005];
int win[400005],lose[400005];
int sp[400005][20];
ll co[400005][20],d[400005];
vec v[400005];
void dfs(int x) {
for(int i : v[x]) {
d[i] = d[x]+s[i];
sp[i][0] = x;
co[i][0] = d[i]+s[i];
dfs(i);
}
}
void init(int N,vec S,vec P,vec Win,vec Lose) {
n = N;
for(int i = 0;i < n;i++) {
s[i] = S[i], p[i] = P[i];
}
for(int i = 0;i < n;i++) {
win[i] = Win[i], lose[i] = Lose[i];
v[win[i]].pb(i);
}
dfs(n);
sp[n][0] = n;
co[n][0] = d[n]+s[n];
for(int i = 1;i < 20;i++) {
for(int j = 0;j <= n;j++) {
sp[j][i] = sp[sp[j][i-1]][i-1];
co[j][i] = max(co[j][i-1],co[sp[j][i-1]][i-1]);
}
}
}
ll simulate(int x,int z) {
ll he = z;
for(;1;) {
int wi = x;
for(int i = 19;i >= 0;i--) {
if(d[x]+he >= co[wi][i]) wi = sp[wi][i];
}
if(wi == n) {
he += d[x];
break;
}
he = d[x]-d[wi]+he+p[wi];
x = lose[wi];
}
return he;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
9736 KB |
Output is correct |
2 |
Correct |
6 ms |
9676 KB |
Output is correct |
3 |
Correct |
8 ms |
10240 KB |
Output is correct |
4 |
Correct |
63 ms |
25072 KB |
Output is correct |
5 |
Correct |
10 ms |
10300 KB |
Output is correct |
6 |
Correct |
62 ms |
25028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
10060 KB |
Output is correct |
2 |
Correct |
489 ms |
152440 KB |
Output is correct |
3 |
Correct |
478 ms |
163828 KB |
Output is correct |
4 |
Correct |
469 ms |
163908 KB |
Output is correct |
5 |
Correct |
618 ms |
132880 KB |
Output is correct |
6 |
Correct |
523 ms |
152412 KB |
Output is correct |
7 |
Correct |
486 ms |
163876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
10060 KB |
Output is correct |
2 |
Correct |
101 ms |
25756 KB |
Output is correct |
3 |
Correct |
93 ms |
28252 KB |
Output is correct |
4 |
Correct |
90 ms |
29608 KB |
Output is correct |
5 |
Correct |
83 ms |
28156 KB |
Output is correct |
6 |
Execution timed out |
7024 ms |
25796 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
10060 KB |
Output is correct |
2 |
Correct |
101 ms |
25756 KB |
Output is correct |
3 |
Correct |
93 ms |
28252 KB |
Output is correct |
4 |
Correct |
90 ms |
29608 KB |
Output is correct |
5 |
Correct |
83 ms |
28156 KB |
Output is correct |
6 |
Execution timed out |
7024 ms |
25796 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
10060 KB |
Output is correct |
2 |
Correct |
101 ms |
25756 KB |
Output is correct |
3 |
Correct |
93 ms |
28252 KB |
Output is correct |
4 |
Correct |
90 ms |
29608 KB |
Output is correct |
5 |
Correct |
83 ms |
28156 KB |
Output is correct |
6 |
Execution timed out |
7024 ms |
25796 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
10060 KB |
Output is correct |
2 |
Correct |
489 ms |
152440 KB |
Output is correct |
3 |
Correct |
478 ms |
163828 KB |
Output is correct |
4 |
Correct |
469 ms |
163908 KB |
Output is correct |
5 |
Correct |
618 ms |
132880 KB |
Output is correct |
6 |
Correct |
523 ms |
152412 KB |
Output is correct |
7 |
Correct |
486 ms |
163876 KB |
Output is correct |
8 |
Correct |
9 ms |
10060 KB |
Output is correct |
9 |
Correct |
101 ms |
25756 KB |
Output is correct |
10 |
Correct |
93 ms |
28252 KB |
Output is correct |
11 |
Correct |
90 ms |
29608 KB |
Output is correct |
12 |
Correct |
83 ms |
28156 KB |
Output is correct |
13 |
Execution timed out |
7024 ms |
25796 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |