이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int n;
vector<pair<ll, ll>> G, W;
vl dp;
int 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);
}
}
ll simulate(int x, int z) {
if (z >= W[0].first) return z + dp[x];
ll currStrength = z, currCnt = 0;
vi cnt(n);
vl strength(n);
int idx = -1;
for (int i = x; i != n; ) {
currCnt++;
if (cnt[i] != 0) {
idx = i;
break;
}
cnt[i] = currCnt;
strength[i] = currStrength;
if (currStrength >= W[i].first) {
currStrength += W[i].first;
i = G[i].first;
} else {
currStrength += W[i].second;
i = G[i].second;
}
}
if (idx == -1) return currStrength;
if (currStrength >= W[0].first) {
return currStrength + dp[idx];
}
ll cycleStrength = currStrength-strength[idx];
ll remStrength = W[0].first-currStrength;
currStrength += (remStrength/cycleStrength)*cycleStrength;
int idx2 = -1;
for (int i = idx; i != n; ) {
if (currStrength >= W[0].first) {
idx2 = i;
break;
}
if (currStrength >= W[i].first) {
currStrength += W[i].first;
i = G[i].first;
} else {
currStrength += W[i].second;
i = G[i].second;
}
}
if (idx2 == -1) return currStrength;
return currStrength + dp[idx2];
}
# | 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... |