제출 #1056166

#제출 시각아이디문제언어결과실행 시간메모리
1056166fuad27Dungeons Game (IOI21_dungeons)C++17
100 / 100
6605 ms962900 KiB
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2,lzcnt,popcnt")
const int N = 4e5+1;
const int lg = 25;
const int lgb = 6;
const int base = 8;
const int inf = 2e9;
int up[lg][N][lgb];
int min_diff[lg][N][lgb];
long long sum[lg][N][lgb];
int n;
vector<int> s, p, w, l;
void init(int nn, std::vector<int> ss, std::vector<int> pp,
		std::vector<int> ww, std::vector<int> ll) {
	n = nn;
	swap(ss, s);
	swap(pp, p);
	swap(ww, w);
	swap(ll, l);
	for(int i = 0;i<n;i++) {
		int _=0;
		for(_ = 0;(1ll<<_)<=s[i];_++) {
				up[_][i][0] = l[i];
				min_diff[_][i][0] = s[i];
				sum[_][i][0] = p[i];
		}
		for(;_<lg;_++) {
				up[_][i][0] = w[i];
				min_diff[_][i][0] = inf;
				sum[_][i][0] = s[i];
		}
	}
	for(int _ = 0;_<lg;_++) {
		up[_][n][0] = n;
		min_diff[_][n][0] = inf;
		sum[_][n][0] = 0;
	}
	for(int _ = 0;_<lg;_++) {
		for(int l = 1;l<lgb;l++) {
			for(int i = 0;i<=n;i++) {
				int at = i;
				min_diff[_][i][l]=inf;
				for(int k = 0;k<base;k++) {
					if(min_diff[_][at][l-1] != inf)
						min_diff[_][i][l] = max(0ll, min((long long)min_diff[_][i][l], min_diff[_][at][l-1]-sum[_][i][l]));
					sum[_][i][l]+=sum[_][at][l-1];
					at=up[_][at][l-1];
				}
				up[_][i][l] = at;
			}
		}
	}
	return;
}
 
long long simulate(int x, int zz) {
	long long z = zz;
	int cnt=0;
	int idx=0;
	while(1) {
		if(x == n)break;
		cnt++;
		while((1ll<<idx) <= z) {
			idx++;
		}
		int ll = min(lg-1, idx-1);
		for(int j = lgb-1;j>=0;j--) {
			for(int _ = 1;_<base;_++) {
				if(up[ll][x][j] == n or (ll < lg-1 and min_diff[ll][x][j] <= z))break;
				z += sum[ll][x][j];
				x = up[ll][x][j];
			}
		}
		if(s[x] <= z) {
			z+=s[x];
			x=w[x];
		}
		else if(s[x] > z) {
			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...