This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> str, ls, wn, lsd;
vector<long long> d;
int N, mx = 0;
void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) {
d.resize(n + 2, 0);
N = n, str = s, ls = p, wn = w, lsd = l;
vector<int> g[n + 2];
for (int i = 0; i < w.size(); i++) {
g[w[i]].push_back(i);
}
for (auto x : s) mx = max(mx, x);
int pos = n;
set<int> st;
queue<pair<long long, int>> q;
q.push({0, n});
bool visited[n + 2];
memset(visited, 0, sizeof(visited));
visited[n] = 1;
while (q.size() > 0) {
auto node = q.front();
q.pop();
for (auto x : g[node.second]) {
if (!visited[x]) {
visited[x] = 1;
d[x] = node.first + s[x];
q.push({d[x], x});
}
}
}
return;
}
long long simulate(int x, int z) {
long long ans = z;
while (x != N) {
if (ans >= mx) {
ans += d[x];
break;
}
if (ans >= str[x]) {
ans += str[x];
x = wn[x];
}
else {
ans += ls[x];
x = lsd[x];
}
}
return ans;
}
Compilation message (stderr)
dungeons.cpp: In function 'void init(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
dungeons.cpp:13:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for (int i = 0; i < w.size(); i++) {
| ~~^~~~~~~~~~
dungeons.cpp:17:6: warning: unused variable 'pos' [-Wunused-variable]
17 | int pos = n;
| ^~~
# | 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... |