#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 400000;
bool processed[MAX_N] = {false};
long long cycle[MAX_N];
vector<int> s,p,w,l;
queue<int> q;
int n;
void proc(int i, long long sz) {
if (processed[i] || i == n) {
if (i == n) sz = LLONG_MAX;
while(!q.empty()) {
int x = q.front(); q.pop();
cycle[i] = sz;
}
return;
}
processed[i] = true;
proc(l[i], sz + p[i]);
}
void init(int nn, vector<int> ss, vector<int> pp, vector<int> ww, vector<int> ll) {
s = ss; p = pp; w = ww; l = ll; n = nn;
for (int i = 0; i < n; i++) {
if (!processed[i]) proc(i, 0);
}
return;
}
long long simulate(int x, int z) {
z += (s[x] - z) / cycle[x] * cycle[x];
int pos = x;
while (z < s[x]) {
z += p[pos];
pos = l[pos];
}
return z;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |