이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int n;
vector<pair<ll, ll>> G, W;
vl dp;
const int LOG = 30;
vvi up;
vvl sum;
vi visited;
ll getDP(int i) {
if (dp[i] != -1) return dp[i];
if (i == n) {
dp[i] = 0;
return 0;
}
dp[i] = W[i].first+getDP(G[i].first);
return dp[i];
}
void init(int nx, vi s, vi p, vi w, vi l) {
n = nx;
G = vector<pll>(n);
W = vector<pll>(n);
for (int i = 0; i < n; i++) {
G[i] = {w[i], l[i]};
W[i] = {s[i], p[i]};
}
dp = vl(n+1, -1);
for (int i = 0; i <= n; i++) {
dp[i] = getDP(i);
}
up = vvi(n+1, vi(LOG));
sum = vvl(n+1, vl(LOG));
for (int i = 0; i < n; i++) {
up[i][0] = G[i].second;
sum[i][0] = W[i].second;
}
up[n][0] = n;
for (int i = 1; i < LOG; i++) {
up[n][i] = n;
for (int v = 0; v < n; v++) {
sum[v][i] = sum[v][i-1] + sum[up[v][i-1]][i-1];
up[v][i] = up[up[v][i-1]][i-1];
}
}
}
pll dist(int x, int d) {
ll strength = 0;
for (int i = LOG-1; i >= 0; i--) {
if ((d>>i)&1) {
strength += sum[x][i];
x = up[x][i];
}
}
return {x, strength};
}
ll simulate(int x, int z) {
if (z >= W[0].first) {
return z + dp[x];
}
int lo = 0, hi = 1e7+6, res, mid;
while (lo <= hi) {
mid = (lo+hi)/2;
if (dist(x, mid).second+z >= W[0].first) {
res = mid;
hi = mid -1;
} else
lo = mid + 1;
}
lo = 0, hi = res-1;
int res2 = -1;
while (lo <= hi) {
mid = (lo+hi)/2;
if (dist(x, mid).first == n) {
res2 = mid;
hi = mid - 1;
} else
lo = mid + 1;
}
if (res2 != -1) {
return z+dist(x, res2).second;
}
return z + dist(x, res).second + dp[dist(x, res).first];
// return strength+sum[x][0]+dp[up[x][0]];
}
컴파일 시 표준 에러 (stderr) 메시지
dungeons.cpp: In function 'll simulate(int, int)':
dungeons.cpp:107:49: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
107 | return z + dist(x, res).second + dp[dist(x, res).first];
| ^
# | 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... |