제출 #1242891

#제출 시각아이디문제언어결과실행 시간메모리
1242891trimkusDungeons Game (IOI21_dungeons)C++20
0 / 100
7089 ms7812 KiB
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> S, P, W, L;
int N;
const int MAXN = 5e4 + 1;
vector<int> adj[MAXN + 1];
ll cost[MAXN + 1];
ll cycle_cost[MAXN + 1];
bool cycle[MAXN + 1];


void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) {
	N = n;
	S = s;
	P = p;
	W = w;
	L = l;
	S.push_back(0);
	for (int i = 0; i < n; ++i) {
		adj[w[i]].push_back(i);
	}
	auto dfs = [&](auto& dfs, int i, ll now) -> void {
		now += S[i];
		cost[i] = now;
		for (auto& u : adj[i]) {
			dfs(dfs, u, now);
		}
	};
	dfs(dfs, n, 0);
	// for (int i = 0; i < n; ++i) {
	// 	cerr << cost[i] << " ";
	// }
	// cerr << "\n";
	vector<bool> vis(n);
	for (int i = 0; i < n; ++i) {
		if (vis[i]) continue;
		int j = i;
		while (!vis[j]) {
			vis[j] = true;
			j = L[j];
		}
		if (cycle[j]) continue;
		int y = j;
		ll tot = 0;
		// cerr << y << "\n";
		bool ok = true;
		do {
			if (cycle[y] || y == n) {
				ok = false;
				break;
			}
			tot += P[y];
			y = L[y];
		} while (y != j);
		if (!ok) continue;
		do {
			cycle[y] = 1;
			cycle_cost[y] = tot;
			y = L[y];
		} while (y != j);
	}
	// for (int i = 0; i <= n; ++i) {
	// 	cout << cycle[i] << " ";
	// }
	// cout << "\n";
	return;
}

long long simulate(int x, int z) {
	ll res = z;
	ll tot = 0;
	while (x != N && res < S[0] && !cycle[x]) {
		res += P[x];
		x = L[x];
	}
	if (x == N) return res;
	if (res >= S[0]) {
		return res + cost[x];
	}
	// cerr << x << " " << res << " " << tot << "\n";
	tot = cycle_cost[x];
	// cerr << tot << " ";
	res += (S[0] - res) / tot * tot;
	// cerr << res << " " << "\n";
	while (x != N && res < S[0]) {
		res += P[x];
		x = L[x];
	}
	// cerr << res << " " << x << "\n";
	res += cost[x];
	return res;
}

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