이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define debug(...) //ignore
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long double ld;
int n;
vi s, p, w, l;
ll LG1 = 27;
struct T {
int node;
ll gain;
ll max_strength;
};
T f(T a, T b) {
T res;
res.node = b.node;
res.gain = a.gain + b.gain;
res.max_strength = min(a.max_strength, b.max_strength - a.gain);
return res;
}
vector<vector<vector<T>>> jmp;
void ini() {
jmp.resize(LG1);
rep(a,0,LG1) {
if(a % 4 != 0) continue;
ll z = 1LL<<a;
jmp[a].assign(log2(z)+1, vector<T>(n+1));
rep(i,0,n) {
if(z >= s[i]) jmp[a][0][i] = T{w[i], ll(s[i]), ll(1e18)};
else jmp[a][0][i] = T{l[i], ll(p[i]), ll(s[i]-1)};
}
jmp[a][0][n] = T{n, ll(0), ll(-1)}; // immediately loose when enter node n
rep(k,1,sz(jmp[a])) rep(i,0,n+1)
jmp[a][k][i] = f(jmp[a][k-1][i], jmp[a][k-1][jmp[a][k-1][i].node]);
}
}
ll sim(int x, ll z, int a) {
if(x == n) return z;
assert(a%4 == 0);
assert(z >= (1LL<<a));
assert(a < LG1);
if(z >= (1LL<<(a+4))) return sim(x,z,a+4);
for(int k = sz(jmp[a]); k--;) {
if(x == n) return z;
auto v = jmp[a][k][x];
if(z <= v.max_strength) {
z += v.gain;
x = v.node;
}
}
if(x == n) return z;
if(z >= s[x]) return sim(w[x], z+s[x], a);
else return sim(l[x], z+p[x], a);
}
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; ini(); return; }
ll simulate(int x, int z) { return sim(x,z,0); }
# | 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... |