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;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
typedef long long ll;
typedef vector<int> vi;
int n;
vi s, p, w, l;
const int VLS = 30, ME = 20, MN = 5e4 + 10;
vi skp;
struct ch{int t; ll by, thl;};
ch bjp[VLS][MN][ME];
const ll INF = 1e16;
void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) {
::n=n;
::s=s, ::p=p, ::w=w, ::l=l;
skp.push_back(0);
forR(i, VLS) skp.push_back(1 << i);
forR(si, VLS) {
int val = skp[si];
forR(i, n) {
if(s[i] <= val) bjp[si][i][0] = {w[i], (ll) s[i], INF};
else bjp[si][i][0] = {l[i], (ll) p[i], s[i]};
}
REP(e, 1, ME) {
forR(i, n) {
ch nex = bjp[si][i][e-1];
if(nex.t == n) bjp[si][i][e] = nex;
else {
bjp[si][i][e] = {bjp[si][nex.t][e-1].t, bjp[si][nex.t][e-1].by + nex.by, min(nex.thl, bjp[si][nex.t][e-1].thl - nex.by)};
}
}
}
}
}
struct pii{int a; ll b;};
pii tWin(int x, ll z, int igi) {
assert(z >= skp[igi]);
int ci=x; ll cv = z;
for(int e = ME - 1; e >= 0; --e) {
if(ci == n) return {ci, cv};
if(cv < bjp[igi][ci][e].thl) {
cv += bjp[igi][ci][e].by;
ci = bjp[igi][ci][e].t;
}
}
return {ci, cv};
}
long long simulate(int x, int z) {
int ci = x;
ll cv = z;
forR(ind, VLS) {
pii nex = tWin(ci, cv, ind);
if(nex.a == n) {
return nex.b;
}
ci=nex.a;
cv=nex.b;
assert(cv >= s[ci]);
cv += s[ci];
ci = w[ci];
}
return cv;
}
# | 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... |