이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Challenge: Accepted
#include "dungeons.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#define ll long long
#define maxn 400005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
int n;
vector<int> s, p, w, l;
int anc[19][maxn];
ll ma[19][maxn];
ll sum[19][maxn];
void init(int nv, vector<int> sv, vector<int> pv, vector<int> wv, vector<int> lv) {
n = nv;
s = sv, p = pv, w = wv, l = lv;
for (int i = 0;i < n;i++) {
anc[0][i] = w[i];
ma[0][i] = s[i];
sum[0][i] = s[i];
}
anc[0][n] = n;
for (int i = 1;i < 19;i++) {
for (int j = 0;j <= n;j++) {
anc[i][j] = anc[i-1][anc[i-1][j]];
sum[i][j] = sum[i-1][j] + sum[i-1][anc[i-1][j]];
ma[i][j] = max(ma[i-1][j], ma[i-1][anc[i-1][j]] - sum[i-1][j]);
}
}
}
void wins(int &x, ll &val) { //brings it to the nearest loss
for (int i = 18;i >= 0;i--) {
if (val >= ma[i][x]) {
val += sum[i][x];
x = anc[i][x];
}
}
}
long long simulate(int x, int z) {
ll ans = z;
while (x != n) {
wins(x, ans);
if (x == n) break;
ans += p[x];
x = l[x];
}
return ans;
}
/*
3 2
2 6 9
3 1 2
2 2 3
1 0 1
0 1
2 3
*/
# | 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... |