이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "dungeons.h"
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
const int nax = 5e4 + 5;
const ll INF = 1e7;
const int LG = 25;
const int LG2 = 13;
const int b = 4;
int n;
vi S, P, W, L;
int sp[nax][LG2][LG];
ll mini[nax][LG2][LG];
ll ps[nax][LG2][LG];
ll POW[LG2];
void init(int N, vi s, vi p, vi w, vi l)
{
n = N, S = s, P = p, W= w, L = l;
S.pb(0);
W.pb(n);
POW[0] = 1ll;
for(int i =1; i < LG2; i++)
POW[i] = (POW[i - 1] * 1ll * b);
for(int i = 0; i <= n; i++)
{
for(int l = 0; l < LG2; l++)
{
if(S[i] <= POW[l])
{
sp[i][l][0] = W[i];
mini[i][l][0] = INF * 1ll * INF;
ps[i][l][0] = S[i];
}
else
{
sp[i][l][0] = L[i];
mini[i][l][0] = S[i];
ps[i][l][0] = P[i];
}
}
}
for(int j = 1; j < LG; j++)
{
for(int i = 0; i <= n; i++)
{
for(int l = 0; l < LG2; l++)
{
sp[i][l][j] = sp[sp[i][l][j - 1]][l][j - 1];
mini[i][l][j] = min(mini[i][l][j - 1], mini[sp[i][l][j - 1]][l][j - 1] - ps[i][l][j - 1]);
ps[i][l][j] = ps[i][l][j - 1] + ps[sp[i][l][j - 1]][l][j - 1];
}
}
}
}
pair<int,ll> check(int i, ll z)
{
ll delta = 0ll;
int l = 0;
while((l < LG2) && POW[l] <= z)
l++;
l--;
if((S[i] > POW[l]) && (S[i] <= z))
return {i, 0ll};
//cout << '\t' << i << ' ' << z << ' ' << l << '\n';
for(int j = LG - 1; j >= 0; j--)
{
bool cond = (mini[i][l][j] - delta <= z) || (sp[i][l][j] == n);
if(!(cond))
{
delta += ps[i][l][j];
i = sp[i][l][j];
}
}
if(z + delta < mini[i][l][0])
{
delta += ps[i][l][0];
i = sp[i][l][0];
}
return {i, delta};
}
ll simulate(int x, int Z)
{
ll z = Z;
while(x != n)
{
// cout << x << ' ' << z << '\n';
pair<int,ll> u = check(x, z);
x = u.ff;
z += u.ss;
z += S[x];
x = W[x];
}
return z;
}
/*
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
/*
int n, q;
cin >> n >> q;
vi s(n), p(n), w(n), l(n);
for(int i = 0; i < n; i++)
cin >> s[i];
for(int i = 0; i < n; i++)
cin >> p[i];
for(int i =0 ;i < n; i++)
cin >> w[i];
for(int i = 0;i < n; i++)
cin >> l[i];
init(n, s, p, w, l);
while(q--)
{
int x, z;
cin >> x >> z;
cout << simulate(x, z) << '\n';
}
init(3, {2, 6, 9}, {3, 1, 2}, {2, 2, 3}, {1, 0, 1});
cout << simulate(0, 1) << '\n';
cout << simulate(2, 3) << '\n';
}
*/
컴파일 시 표준 에러 (stderr) 메시지
dungeons.cpp:113:5: warning: "/*" within comment [-Wcomment]
113 | /*
|
# | 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... |