Submission #992158

# Submission time Handle Problem Language Result Execution time Memory
992158 2024-06-04T04:28:38 Z pavement Dungeons Game (IOI21_dungeons) C++17
0 / 100
110 ms 226248 KB
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define pb push_back

const int MAX_N = 50000, BAND_LIM = 23, DECOMP_LIM = 23;
int n, to[BAND_LIM][DECOMP_LIM][MAX_N + 1];
ll wei[BAND_LIM][DECOMP_LIM][MAX_N + 1], lim[BAND_LIM][DECOMP_LIM][MAX_N + 1];
vector<int> s, p, w, l;

void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) {
	::n = n;
	::s = s;
	::p = p;
	::w = w;
	::l = l;
	s.pb(0);
	p.pb(0);
	w.pb(n);
	l.pb(n);
	for (int b = 0; b < BAND_LIM; b++) {
		int lb = (1 << b), rb = (1 << (b + 1)) - 1;
		for (int i = 0; i <= n; i++) {
			if (s[i] < lb) { // instant-win
				to[b][0][i] = w[i];
				wei[b][0][i] = s[i];
				lim[b][0][i] = (ll)1e16;
			} else if (s[i] > rb) { // instant-lose
				to[b][0][i] = l[i];
				wei[b][0][i] = p[i];
				lim[b][0][i] = (ll)1e16;
			} else {
				to[b][0][i] = l[i];
				wei[b][0][i] = p[i];
				lim[b][0][i] = s[i];
			}
		}
		for (int k = 1; k < DECOMP_LIM; k++) {
			for (int i = 0; i <= n; i++) {
				to[b][k][i] = to[b][k - 1][to[b][k - 1][i]];
				wei[b][k][i] = wei[b][k - 1][i] + wei[b][k - 1][to[b][k - 1][i]];
				lim[b][k][i] = min(lim[b][k - 1][i], lim[b][k - 1][to[b][k - 1][i]] - wei[b][k - 1][i]);
			}
		}
	}
}

ll simulate(int x, int z) {
	for (int b = 0; b < BAND_LIM; b++) {
		int rb = (1 << (b + 1)) - 1;
		if (z > rb) { // past this band
			continue;
		}
		for (int k = DECOMP_LIM - 1; k >= 0; k--) {
			if (lim[b][k][x] <= z || z + wei[b][k][x] > rb) {
				continue;
			}
			z += wei[b][k][x];
			x = to[b][k][x];
		}
		for (int iter = 0; iter < 2; iter++) {
			if (z >= s[x]) {
				z += s[x];
				x = w[x];
			} else {
				z += p[x];
				x = l[x];
			}
			if (x == n) {
				return z;
			}
		}
	}
	assert(0);
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 92760 KB Output is correct
2 Correct 10 ms 94812 KB Output is correct
3 Runtime error 110 ms 226248 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 102 ms 216860 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 105 ms 212920 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 105 ms 212920 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 105 ms 212920 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 102 ms 216860 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -