Submission #1048538

#TimeUsernameProblemLanguageResultExecution timeMemory
1048538parsadox2Dungeons Game (IOI21_dungeons)C++17
37 / 100
129 ms36180 KiB
#include "dungeons.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 4e5 + 10 , Sq = 1000 , B = N / Sq + 2 , inf = 1e7;

int n , nex[N];
long long dis[N] , val[N];
vector <int> s , p , w , l;

void init(int nn, vector<int> ss, vector<int> pp, vector<int> ww, vector<int> ll) {
	n = nn;
	s = ss;
	p = pp;
	w = ww;
	l = ll;
	dis[n] = 0;
	nex[n] = n;
	for(int i = n - 1 ; i >= 0 ; i--)
	{
		dis[i] = dis[w[i]] + s[i];
		if(s[i] >= Sq)
		{
			nex[i] = i;
			val[i] = 0;
		}
		else
		{
			nex[i] = nex[w[i]];
			val[i] = s[i] + val[w[i]];
		}
	}
	return;
}

long long simulate(int x, int z) {
	while(z < Sq && x != n)
	{
		if(z >= s[x])
		{
			z += s[x];
			x = w[x];
		}
		else
		{
			z += p[x];
			x = l[x];
		}
	}
	if(x == n)
		return z;
	while(z < inf)
	{
		z += val[x];
		x = nex[x];
		if(x == n)
			break;
		if(z >= s[x])
		{
			z += s[x];
			x = w[x];
		}
		else
		{
			z += p[x];
			x = l[x];
		}
	}
	z += dis[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...