# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
485836 | rumen_m | Dungeons Game (IOI21_dungeons) | C++17 | 84 ms | 34008 KiB |
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 <vector>
#include <bits/stdc++.h>
using namespace std;
const int maxn = 400005;
const int logn = 35;
long long nextt[maxn][logn],add[maxn][logn];
long long sums[maxn];
bool vis[maxn];
int n;
vector <int> s,p,w,l;
int dfs(int v)
{
if(v==n)return 0;
if(vis[v])return sums[v];
sums[v] = s[v] + dfs(w[v]);
vis[v] = 1;
return sums[v];
}
void init(int _n, std::vector<int> _s, std::vector<int> _p, std::vector<int> _w, std::vector<int> _l) {
int i,j;
n = _n;
s.resize(_s.size());
for(i=0;i<_s.size();i++)
s[i] = _s[i];
p.resize(_p.size());
for(i=0;i<_p.size();i++)
p[i] = _p[i];
w.resize(_w.size());
for(i=0;i<_w.size();i++)
w[i] = _w[i];
l.resize(_l.size());
for(i=0;i<_l.size();i++)
l[i] = _l[i];
for(i=0;i<n;i++)
{
nextt[i][0] = l[i];
add[i][0] = p[i];
}
nextt[n][0] = n;
for(i=1;i<logn;i++)
{
for(j=0;j<=n;j++)
{
nextt[j][i] = nextt[nextt[j][i-1]][i-1];
add[j][i] = add[j][i-1]+add[nextt[j][i-1]][i-1];
}
}
for(i=0;i<=n;i++)
{
dfs(i);
}
}
long long simulate(int x, int z) {
if(x==n)return z;
int S = s[0];
int i;
for(i = logn-1;i>=0;i--)
{
if(z+add[x][i] < S)
{
z+=add[x][i];
x = nextt[x][i];
}
}
if(z<S){
z+=add[x][0];
x = nextt[x][0];}
z+=sums[x];
return z;
}
Compilation message (stderr)
# | 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... |