# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
444260 | urd05 | Dungeons Game (IOI21_dungeons) | C++17 | 0 ms | 0 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 <bits/stdc++.h>
using namespace std;
/*int s[400000];
int p[400000];
int w[400000];
int l[400000];
int n;*/
vector<long long> vec;
typedef pair<long long,long long> P;
int nt[4000001][24];
P table[400001][24];
void init(int nn, vector<int> ss, vector<int> pp, vector<int> ww, vector<int> ll) {
n=nn;
for(int i=0;i<n;i++) {
s[i]=ss[i];
p[i]=pp[i];
w[i]=ww[i];
l[i]=ll[i];
}
for(int i=0;i<=n;i++) {
nt[i][0]=(i==n?n:w[i]);
table[i][0]=P(-s[i],s[i]);
}
for(int j=1;j<24;j++) {
for(int i=0;i<=n;i++) {
nt[i][j]=nt[nt[i][j-1]][j-1];
table[i][j]=P(min(table[i][j-1].first,table[i][j-1].second+table[nt[i][j-1]][j-1].first),table[i][j-1].second+table[nt[i][j-1]][j-1].second);
}
}
return;
}
int getind(int val) {
return upper_bound(vec.begin(),vec.end(),val)-vec.begin();
}
long long simulate(int x, int zz) {
long long z=zz;
while (x!=n) {
for(int i=23;i>=0;i--) {
if (nt[x][i]!=n&&z>=-table[x][i].first) {
z+=table[x][i].second;
x=nt[x][i];
}
}
if (z>=s[x]) {
z+=s[x];
x=w[x];
}
else {
z+=p[x];
x=l[x];
}
}
return z;
}