이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int binary_index[16][400001][25];//index, +, max excluded
uint binary_add[16][400001][25];
uint binary_max[16][400001][25];
ll min(int a, ll b) {
return a < b ? a : b;
}
int N;
vector<int> S, P, W, L;
uint safe_add(uint a, uint b) {
if (a + b < a)
return UINT_MAX;
return a + b;
}
uint safe_sub(uint a, uint b) {
if (a < b)
return 0;
return a - b;
}
void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) {
s.push_back(0);
p.push_back(0);
w.push_back(n);
l.push_back(n);
n++;
N = n;
S = s, P = p, W = w, L = l;
for (int range = 0; range < 16; range++)
{
ll r = 1 << (range + 9);
for (int i = 0; i < n; i++)
{
if (s[i] <= r) {
binary_index[range][i][0] = w[i];
binary_add[range][i][0] = s[i];
binary_max[range][i][0] = UINT_MAX;
} else {
binary_index[range][i][0] = l[i];
binary_add[range][i][0] = p[i];
binary_max[range][i][0] = s[i];
}
}
for (int i = 1; i < 25; i++)
{
for (int ind = 0; ind < n; ind++)
{
int pointer = binary_index[range][ind][i - 1];
binary_index[range][ind][i] = binary_index[range][pointer][i - 1];
binary_add[range][ind][i] = safe_add(binary_add[range][ind][i - 1], binary_add[range][pointer][i - 1]);
binary_max[range][ind][i] = min(binary_max[range][ind][i - 1], safe_sub(binary_max[range][pointer][i - 1], binary_add[range][ind][i - 1]));
}
}
}
}
long long simulate(int x, int z) {
ll t = z;
while (t < 512 && x != N - 1) {
if (t >= S[x]) {
t += S[x];
x = W[x];
} else {
t += P[x];
x = L[x];
}
}
for (int r = 0; r <= 15; r++)
{
for (int s = 24; s >= 0; s--)
{
while (binary_max[r][x][s] > t && binary_add[r][x][s] != UINT_MAX && x != N - 1) {
t += binary_add[r][x][s];
x = binary_index[r][x][s];
}
}
}
return t;
}
# | 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... |