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;
const int base=10,sz=9;
const long long INF=1e18;
int nxt[400001][24][sz+1];
long long mx[400001][24],mn[400001][24][sz],sum[400001][24][sz+1];
vector <int> S,P,ve={1};
void init(int n, vector <int> s, vector <int> p, vector <int> w, vector <int> l){
S=s;
P=p;
for (int i=1;i<sz;i++)
ve.push_back(ve.back()*base);
memset(nxt,-1,sizeof(nxt));
for (int i=0;i<n;i++){
for (int j=0;j<sz;j++)
if (s[i]<=ve[j]){
nxt[i][0][j]=w[i];
sum[i][0][j]=s[i];
mn[i][0][j]=INF;
}
else{
nxt[i][0][j]=l[i];
sum[i][0][j]=p[i];
mn[i][0][j]=s[i];
}
nxt[i][0][sz]=w[i];
mx[i][0]=sum[i][0][sz]=s[i];
}
for (int j=1;j<24;j++){
for (int i=0;i<n;i++)
for (int k=0;k<=sz;k++){
if (nxt[i][j-1][k]==-1)
continue;
int u=nxt[i][j-1][k];
nxt[i][j][k]=nxt[u][j-1][k];
if (k<sz)
mn[i][j][k]=min(mn[i][j-1][k],mn[u][j-1][k]-sum[i][j-1][k]);
else
mx[i][j]=max(mx[i][j-1],mx[u][j-1]-sum[i][j-1][k]);
sum[i][j][k]=sum[i][j-1][k]+sum[u][j-1][k];
}
}
}
long long simulate(int x, int Z){
int b=0,cur=0;
long long z=Z;
while (nxt[x][0][0]!=-1){
while (cur<ve.size()&&ve[cur]<=z)
cur++;
int j=(b?cur-1:sz);
for (int i=(b&&z>10000000?-1:23);i>=0;i--)
if (nxt[x][i][j]!=-1)
if ((b&&z<mn[x][i][j])||(!b&&z>=mx[x][i])){
z+=sum[x][i][j];
x=nxt[x][i][j];
}
b^=1;
}
return z;
}
Compilation message (stderr)
dungeons.cpp: In function 'long long int simulate(int, int)':
dungeons.cpp:49:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | while (cur<ve.size()&&ve[cur]<=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... |