Submission #1232793

#TimeUsernameProblemLanguageResultExecution timeMemory
1232793rythm_of_knightDungeons Game (IOI21_dungeons)C++17
13 / 100
419 ms98888 KiB
#include "dungeons.h"
#include <bits/stdc++.h>
#define ar array
using namespace std;
typedef long long ll;

const int MXN = 4e5 + 45, MXA = 1e7 + 7;
int w[MXN], hlg[MXA], s[MXN], n;
ar <ll, 3> st[24][MXN], g[24][MXN];

void init(int N, vector<int> S, vector<int> p, vector<int> W, vector<int> l) {
	n = N;
	for (int i = 0; i < n; i++)
		s[i] = S[i], w[i] = W[i];
	for (int i = 2; i < MXA; i++)
		hlg[i] = hlg[i >> 1] + 1;
	for (int i = 0; i < n; i++) {
		st[0][i][0] = l[i];
		st[0][i][1] = s[i] + p[i] - s[l[i]];
		st[0][i][2] = max(0ll, st[0][i][1]);
		g[0][i][0] = w[i];
		g[0][i][1] = s[i];
		g[0][i][2] = max(0ll, s[w[i]] - 2ll * s[i]);
	}
	for (int i = 0; i < 24; i++)
		g[i][n][0] = n;
	for (int b = 1; b < 24; b++) {
		for (int i = 0; i < n; i++) {
			int h = st[b - 1][i][0];
			st[b][i][0] = st[b - 1][h][0];
			st[b][i][1] = st[b - 1][i][1] + st[b - 1][h][1];
			st[b][i][2] = max(st[b - 1][i][2], st[b - 1][i][1] + st[b - 1][h][2]);
			h = g[b - 1][i][0];
			g[b][i][0] = g[b - 1][h][0];
			g[b][i][1] = g[b - 1][i][1] + g[b - 1][h][1];
			g[b][i][2] = max(g[b - 1][i][2], max(0ll, g[b - 1][h][2] - g[b - 1][i][1]));
		}
	}
	for (int b = 0; b < 5; b++) {

	}
}

ll simulate(int x, int z) {
	ll cur = z;
	int cnt = 0;
	while (x < n) {
		if (s[x] > cur) {
			ll now = cur - s[x];
			int b = min(23, hlg[s[x] - cur]);
			while (b >= 0) {
				auto &tmp = st[b][x];
				if (tmp[2] + now < 0) {
					now += tmp[1];
					x = tmp[0];
				}
				b--;
			}
			now += st[0][x][1];
			x = st[0][x][0];
			cur = s[x] + now;
		} else {
			int b = 23, sv = x;
			while (b >= 0 && x < n) {
				if (g[b][x][2] <= cur && g[b][x][0] < n) {
					cur += g[b][x][1];
					x = g[b][x][0];
				}
				b--;
			}
			if (s[x] <= cur) {
				cur += s[x];
				x = w[x];
			}
		}
	}
	return cur;
}

// #include "dungeons.h"
// #include <bits/stdc++.h>
// #define ar array
// using namespace std;
// typedef long long ll;

// const int MXN = 4e5 + 45, MXA = 1e7 + 7;
// int s[MXN], w[MXN], hlg[MXA], n;
// ll add[MXN];
// ar <ll, 3> st[24][MXN];
// int nok = 0;

// void init(int N, vector<int> S, vector<int> p, vector<int> W, vector<int> l) {
// 	n = N;
// 	for (int i = 0; i < n; i++)
// 		s[i] = S[i], w[i] = W[i], add[i] = S[i];
// 	for (int i = n - 1; i >= 0; i--) {
// 		ll cur = s[i] + s[i];
// 		while (w[i] < n && s[w[i]] <= cur) {
// 			cur += add[w[i]];
// 			add[i] += add[w[i]];
// 			w[i] = w[w[i]];
// 		}
// 	}
// 	for (int i = 2; i < MXA; i++)
// 		hlg[i] = hlg[i >> 1] + 1;
// 	for (int i = 0; i < n; i++) {
// 		st[0][i][0] = l[i];
// 		st[0][i][1] = s[i] + p[i] - s[l[i]];
// 		st[0][i][2] = max(0ll, st[0][i][1]);
// 	}
// 	for (int b = 1; b < 24; b++) {
// 		for (int i = 0; i < n; i++) {
// 			int h = st[b - 1][i][0];
// 			st[b][i][0] = st[b - 1][h][0];
// 			st[b][i][1] = st[b - 1][i][1] + st[b - 1][h][1];
// 			st[b][i][2] = max(st[b - 1][i][2], st[b - 1][i][1] + st[b - 1][h][2]);
// 		}
// 	}
// }

// ll simulate(int x, int z) {
// 	// if (nok)
// 	// 	return -1;
// 	ll cur = z;
// 	int cnt = 0;
// 	int prv = 0;
// 	while (x < n) {
// 		if (s[x] > cur) {
// 			ll now = cur - s[x];
// 			int b = min(23, hlg[s[x] - cur]);
// 			cout << now << ' ';
// 			while (b >= 0) {
// 				auto &tmp = st[b][x];
// 				if (tmp[2] + now < 0) {
// 					now += tmp[1];
// 					x = tmp[0];
// 				}
// 				b--;
// 			}
// 			cout << x << ' ';
// 			cout << st[0][x][0] << ' ' << st[0][x][1] << ' ' << st[0][x][2] << ' ';
// 			cout << now << ' ';
// 			now += st[0][x][1];
// 			x = st[0][x][0];
// 			cur = s[x] + now;
// 			cout << x << '\n';
// 		} else {
// 			cnt++;
// 			cur += add[x];
// 			if (w[x] < n && s[x] * 2 > s[w[x]])
// 				return -1;
// 			prv = s[x];
// 			x = w[x];
// 		}
// 	}
// 	if (cnt >= 150)
// 		return -1;
// 	return cur;
// }

#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...