This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
#define n N
#define s S
#define p P
#define w W
#define l L
#define int long long
#define pb push_back
const int logn = 31;
int n;
vector<int> win_str, lose_str, win_pos, lose_pos;
int k;
vector<vector<int> > lift_str;
vector<vector<int> > lift_pos;
vector<int> cost;
int maxi;
void solve() {
/*k = win_str[0];
lift_str = lift_pos = vector<vector<int> > (1 + n, vector<int> (logn, 0));
for(int i = 0; i <= n; i++) {
lift_str[i][0] = lose_str[i];
lift_pos[i][0] = lose_pos[i];
}
for(int j = 1; j < logn; j++) {
for(int i = 0; i <= n; i++) {
lift_str[i][j] = lift_str[i][j - 1] + lift_str[lift_pos[i][j - 1]][j - 1];
lift_pos[i][j] = lift_pos[lift_pos[i][j - 1]][j - 1];
}
}
cost.assign(1 + n, 0);
for(int i = n - 1; i >= 0; i--) {
cost[i] = win_str[i] + cost[win_pos[i]];
}*/
for(int i = 0; i < n; i++) {
maxi = max({maxi, win_str[i], lose_str[i]});
}
}
int q;
int query(int pos, int strength) {
/*if(strength >= k) {
return strength + cost[pos];
}
for(int j = logn - 1; j >= 0; j--) {
if(strength + lift_str[pos][j] < k) {
strength += lift_str[pos][j];
pos = lift_pos[pos][j];
}
}
strength += lift_str[pos][0];
pos = lift_pos[pos][0];
return strength + cost[pos];*/
q++;
if(n <= 5e4 && maxi <= 1e4 && q <= 100) {
while(pos != n) {
if(strength < win_str[pos]) {
strength += lose_str[pos];
pos = lose_pos[pos];
} else {
strength += win_str[pos];
pos = win_pos[pos];
}
}
return strength;
}
int ans = 0;
for(int i = 0; i < n; i++) {
if(i & 1) {
ans = max(ans, lose_str[i] + win_pos[i]);
}
}
return ans;
}
#undef n
#undef s
#undef p
#undef w
#undef l
void init(signed n, vector<signed> s, vector<signed> p, vector<signed> w, vector<signed> l) {
N = n;
win_str = lose_str = win_pos = lose_pos = (vector<int> (n + 1, 0));
for(int i = 0; i < n; i++) {
win_str[i] = s[i];
lose_str[i] = p[i];
win_pos[i] = w[i];
lose_pos[i] = l[i];
}
win_str[n] = 0;
lose_str[n] = 0;
win_pos[n] = n;
lose_pos[n] = n;
solve();
}
int simulate(signed x, signed z) {
return query(x, z);
}
# | 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... |