이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
vector<int> S, P, W, L;
vector<int> dist;
void find_dist(int index)
{
if (dist[index]) return;
if (W[index] == N)
{
dist[index] = 1;
return;
}
find_dist(W[index]);
dist[index] = dist[W[index]] + 1;
}
ll target;
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;
target = s[0];
dist = vector<int>(N);
for (int i = 0; i < N; i++)
find_dist(i);
}
ll strength;
vector<int> visited;
queue<int> order;
int cur;
void sim()
{
if (visited[cur] || cur == N || strength >= target) return;
visited[cur] = 1;
order.push(cur);
strength += P[cur];
cur = L[cur];
sim();
}
void final(int index)
{
if (index == N) return;
if (strength >= S[index])
{
strength += S[index];
final(W[index]);
}
else
{
strength += target * dist[cur];
}
}
ll simulate(int x, int z)
{
strength = z;
cur = x;
visited = vector<int>(N);
order = {};
sim();
if (cur == N)
return strength;
if (strength >= target)
{
final(cur);
return strength;
}
while (order.front() != cur)
order.pop();
ll cycle_length = 0;
while (!order.empty())
{
cycle_length += P[order.front()];
order.pop();
}
strength += ((target - strength) / cycle_length) * cycle_length;
final(cur);
return strength;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |