This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
#include "dungeons.h"
int N,S[400000],P[400000],W[400000],L[400000];
int nxt[8][19][400000],mm[8][19][400000];
LLI add[8][19][400000];
void init(int n,vector<int> s,vector<int> p,vector<int> w,vector<int> l) {
int i,j,k,pp = 1;
N = n;
for (i = 0; i < n; i++) S[i] = s[i],P[i] = p[i],W[i] = w[i],L[i] = l[i];
for (i = 0; i < 8; i++) {
for (j = 0; j < n; j++) {
if (S[j] <= pp) nxt[i][0][j] = W[j],add[i][0][j] = S[j],mm[i][0][j] = 1e9;
else nxt[i][0][j] = L[j],add[i][0][j] = P[j],mm[i][0][j] = S[j];
}
for (j = 1; j < 19; j++) {
for (k = 0; k < n; k++) {
if (nxt[i][j-1][k] != n) {
nxt[i][j][k] = nxt[i][j-1][nxt[i][j-1][k]];
add[i][j][k] = add[i][j-1][k]+add[i][j-1][nxt[i][j-1][k]];
mm[i][j][k] = min(mm[i][j-1][k],(int) max(mm[i][j-1][nxt[i][j-1][k]]-add[i][j-1][k],0LL));
}
else nxt[i][j][k] = n;
}
}
pp *= 10;
}
}
long long int simulate(int x,int z) {
int i,j,l = 0,pp = 1;
LLI s = z;
while (x != N) {
while ((l < 7) && (10*pp <= s)) l++,pp *= 10;
for (i = 18; i >= 0; i--) {
if ((nxt[l][i][x] != N) && (min(s,(LLI) 1e7) < mm[l][i][x])) s += add[l][i][x],x = nxt[l][i][x];
}
if (s >= S[x]) s += S[x],x = W[x];
else s += P[x],x = L[x];
}
return s;
}
Compilation message (stderr)
dungeons.cpp: In function 'long long int simulate(int, int)':
dungeons.cpp:85:11: warning: unused variable 'j' [-Wunused-variable]
85 | int i,j,l = 0,pp = 1;
| ^
# | 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... |