Submission #623879

#TimeUsernameProblemLanguageResultExecution timeMemory
623879sofapudenDungeons Game (IOI21_dungeons)C++17
0 / 100
7220 ms2096800 KiB
#include "dungeons.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int mxN = 4e5+5;
const int M = 13;

ll b[mxN][M][17], t[mxN][M][17], a[mxN][M][17];
vector<int> s, p, w, l;
int n;

const ll inf = (1ll<<60);

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;
	for(int i = 0; i < 17; ++i){
		b[n][4][i] = n;
		t[n][4][i] = inf;
		a[n][4][i] = 0;
		for(int k = 0; k < n; ++k){
			if(s[k] <= (1<<i<<8)){
				t[k][4][i] = inf;
				a[k][4][i] = s[k];
				b[k][4][i] = w[k];
			}
			else{
				t[k][4][i] = s[k];
				a[k][4][i] = p[k];
				b[k][4][i] = l[k];
			}
		}
		for(int j = 5; j < 2*M; ++j){
			for(int k = 0; k < n; ++k){
				t[k][j%M][i] = (t[b[k][(j-1)%M][i]][(j-1)%M][i] == inf ? t[k][(j-1)%M][i] : min(t[b[k][(j-1)%M][i]][(j-1)%M][i] - a[k][(j-1)%M][i], t[k][(j-1)%M][i]));
				a[k][j%M][i] = a[b[k][(j-1)%M][i]][(j-1)%M][i] + a[k][(j-1)%M][i];
				b[k][j%M][i] = b[b[k][(j-1)%M][i]][(j-1)%M][i];
			}
		}
	}
}

ll simulate(int x, int _z) {
	ll z = _z;
	while(z <= 256 && x != n) {
		if(z >= s[x]){
			z += s[x];
			x = w[x];
		} else {
			z += p[x];
			x = l[x];
		}
	}
	if(x != n){
		for(int i = 0; i < 17; ++i){
			for(int j = M; ~j; --j){
				while(x != n && z < t[x][j][i]){
					z += a[x][j][i];
					x = b[x][j][i];
				}
			}
			while(x != n && z <= (1<<i<<9)){
				if(z >= s[x]){
					z += s[x];
					x = w[x];
				} else {
					z += p[x];
					x = l[x];
				}
			}
			if(x == n)break;
		}
		while(x != n) {
			if(z >= s[x]){
				z += s[x];
				x = w[x];
			} else {
				z += p[x];
				x = l[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...