제출 #1034898

#제출 시각아이디문제언어결과실행 시간메모리
1034898Boas던전 (IOI21_dungeons)C++17
37 / 100
7048 ms313644 KiB

#include <bits/stdc++.h>
using namespace std;

#define loop(x, i) for (int i = 0; i < x; i++)
#define rev(x, i) for (int i = (int)x - 1; i >= 0; i--)
#define loop1(x, i) for (int i = 1; i <= x; i++)
#define ALL(x) begin(x), end(x)
#define pb push_back
#define int long long

typedef vector<int> vi;
typedef vector<signed> vi32;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;

#include "dungeons.h"

int N;
vi32 S, P, W, L;
vvi winP, winD, maxS;

void init(signed n, vi32 s, vi32 p, vi32 w, vi32 l)
{
	N = n;
	S = s;
	P = p;
	W = w;
	L = l;
	winP = maxS = winD = vvi(30, vi(n + 1));
	loop(n, i)
	{
		winD[0][i] = s[i];
		maxS[0][i] = s[i];
		winP[0][i] = w[i];
	}
	winD[0][n] = 0;
	maxS[0][n] = 0;
	winP[0][n] = n;
	loop1(29, x)
	{
		loop(n + 1, i)
		{
			int halfW = winP[x - 1][i];
			winP[x][i] = winP[x - 1][halfW];
			winD[x][i] = winD[x - 1][i] + winD[x - 1][halfW];
			maxS[x][i] = max(maxS[x - 1][i], maxS[x - 1][halfW]);
		}
	}
}

int simulate(signed a, signed b)
{
	int x = a, z = b;
	auto runLosses = [&]() -> int
	{
		while (x != N && z < S[x])
		{
			z += P[x];
			x = L[x];
		}
		if (x == N)
			return z;
		return -1;
	};
	if (z < S[x])
	{
		int res = runLosses();
		if (res != -1)
			return res;
	}
	while (winP[0][x] != N)
	{
		rev(30, j)
		{
			if (winP[j][x] != N && z >= maxS[j][x])
			{
				z += winD[j][x];
				x = winP[j][x];
			}
		}
		if (z < S[x])
		{
			int res = runLosses();
			if (res != -1)
				return res;
		}
	}
	z += winD[0][x];
	x = winP[0][x];
	return z;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...