Submission #1195791

#TimeUsernameProblemLanguageResultExecution timeMemory
1195791belgianbotDungeons Game (IOI21_dungeons)C++20
0 / 100
2 ms3652 KiB
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 400000;
vector<bool> processed(MAX_N,false);
vector<long long> cycle(MAX_N);
vector<int> s,p,w,l;
queue<int> q;
int n;

void proc(int i, long long sz) {
	if (processed[i] || i == n) {
		if (i == n) sz = LLONG_MAX;
		while(!q.empty()) {
			int x = q.front(); q.pop();
			cycle[x] = sz;
		}
		return;
	}
	processed[i] = true;
	q.push(i);
	proc(l[i], sz + p[i]);
}
void init(int nn, vector<int> ss, vector<int> pp, vector<int> ww, vector<int> ll) {
	s = ss; p = pp; w = ww; l = ll; n = nn;
	for (int i = 0; i < n; i++) {
		if (!processed[i]) proc(i, 0);
	}
	return;
}

long long simulate(int x, int z) {
	if (z >= s[x]) return z;
	long long st = z;
	st += (s[x] - st) / cycle[x] * cycle[x];
	int pos = x;
	while (st < s[x]) {
		st += p[pos];
		pos = l[pos];
	}
	return st;
}

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