이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=4e5+5, lx=8, kx=25;
ll N, pw[20], dist[nx];
vector<int> S(nx), P(nx), W(nx), L(nx);
struct edge
{
int out;
ll cost, t;
edge(int out=0, ll cost=0, ll t=0): out(out), cost(cost), t(t){}
} dp[lx][nx][kx];
void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) {
N=n;
pw[0]=1;
for (int i=1; i<20; i++) pw[i]=pw[i-1]*8;
for (int i=0; i<n; i++) S[i]=s[i], P[i]=p[i], W[i]=w[i], L[i]=l[i];
for (int i=n-1; i>=0; i--) dist[i]=dist[w[i]]+s[i];
W[n]=L[n]=n;
for (int i=0; i<lx; i++)
{
for (int u=0; u<=n; u++)
{
if (s[u]<=pw[i]) dp[i][u][0]=edge(W[u], S[u], 1e18);
else dp[i][u][0]=edge(L[u], P[u], S[u]);
}
for (int j=1; j<kx; j++)
{
for (int u=0; u<=n; u++)
{
int v=dp[i][u][j-1].out;
ll out=dp[i][v][j-1].out;
ll cost=dp[i][u][j-1].cost+dp[i][v][j-1].cost;
ll t=min(dp[i][u][j-1].t, dp[i][v][j-1].t-dp[i][u][j-1].cost);
dp[i][u][j]=edge(out, cost, t);
}
}
}
}
long long simulate(int x, int z) {
ll cur=z, st=0;
while (x!=N&&cur<1e7)
{
//cout<<"debug "<<x<<' '<<cur<<' '<<st<<'\n';
while (st+1<lx&&pw[st+1]<=cur) st++;
for (int i=kx-1; i>=0; i--) if (dp[st][x][i].t>cur) cur+=dp[st][x][i].cost, x=dp[st][x][i].out; //cout<<"here "<<i<<' '<<cur<<' '<<x<<'\n';
//cout<<"after "<<x<<' '<<cur<<' '<<st<<'\n';
if (cur>=S[x]) cur+=S[x], x=W[x];
else cur+=P[x], x=L[x];
}
return cur+dist[x];
}
# | 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... |