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;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 5e4+5;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
int N;
pair<int,ll> dp[7][25][MAXN];
vector<int> pos_s, S, P, W, L;
void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) {
set<int> aux;
N = sz(s);
for(int i = 0; i < N; i++) aux.insert(s[i]);
for(auto it : aux) pos_s.pb(it);
if(sz(pos_s) > 5) {
S = s;
P = p;
W = w;
L = l;
return;
}
s.pb(0); p.pb(0); w.pb(N); l.pb(N);
for(int i = 0; i <= N; i++) {
int it = lower_bound(all(pos_s), s[i]) - pos_s.begin();
for(int j = 0; j <= 6; j++) {
if(it < j) dp[j][0][i] = {w[i], s[i]};
else dp[j][0][i] = {l[i], p[i]};
}
}
for(int t = 0; t <= 6; t++) {
for(int bit = 1; bit < 25; bit++) {
for(int i = 0; i <= N; i++) {
dp[t][bit][i].fr = dp[t][bit-1][dp[t][bit-1][i].fr].fr;
dp[t][bit][i].sc = dp[t][bit-1][i].sc + dp[t][bit-1][dp[t][bit-1][i].fr].sc;
}
}
}
}
ll simulate(int x, int z) {
int t = 0;
ll ans = z;
if(!S.empty()) {
while(x != N) {
if(ans >= S[x]) ans += S[x], x = W[x];
else ans += P[x], x = L[x];
}
return ans;
}
while(t < sz(pos_s)) {
// dp[t][][x]
for(int bit = 24; bit >= 0; bit--) {
if(ans + dp[t][bit][x].sc < pos_s[t])
ans += dp[t][bit][x].sc, x = dp[t][bit][x].fr;
}
if(ans < pos_s[t]) ans += dp[t][0][x].sc, x = dp[t][0][x].fr;
t++;
}
ans += dp[t][24][x].sc;
return ans;
}
# | 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... |