# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
444231 | 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<int,long long> P;
P table[400001][24][6];
P nt[400001][6];
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++) {
vec.push_back(s[i]);
}
sort(vec.begin(),vec.end());
vec.erase(unique(vec.begin(),vec.end()),vec.end());
for(int i=0;i<n;i++) {
s[i]=lower_bound(vec.begin(),vec.end(),s[i])-vec.begin();
}
for(int j=0;j<=vec.size();j++) {
for(int i=0;i<=n;i++) {
if (i==n) {
nt[i][j]=P(i,0);
table[i][0][j]=nt[i][j];
continue;
}
if (j>s[i]) {
nt[i][j]=P(w[i],vec[s[i]]);
}
else {
nt[i][j]=P(l[i],p[i]);
}
table[i][0][j]=nt[i][j];
}
}
for(int j=1;j<24;j++) {
for(int k=0;k<6;k++) {
for(int i=0;i<=n;i++) {
table[i][j][k]=P(table[table[i][j-1][k].first][j-1][k].first,table[i][j-1][k].second+table[table[i][j-1][k].first][j-1][k].second);
}
}
}
vec.push_back(1e12);
return;
}
int getind(int val) {
return lower_bound(vec.begin(),vec.end(),val)-vec.begin();
}
long long simulate(int x, long long z) {
while (x!=n) {
int ind=getind(z);
int now=x;
for(int i=23;i>=0;i--) {
P nt=table[now][i][ind];
if (getind(z+nt.second)!=ind||nt.first==n) {
continue;
}
now=nt.first;
z+=nt.second;
}
z+=nt[now][ind].second;
now=nt[now][ind].first;
x=now;
//printf("%d %d\n",x,z);
}
return z;
}