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<bits/stdc++.h>
#include"dungeons.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
int n;
int INF = 1e7+10;
vector<int>s,p,w,l;
vector<ll>wins(5e4+5,0ll);
vector<pll>ls(5e4+5);
vector<unordered_map<int,int>>mp(5e4+5);
set<int>st;
void init(int N,vector<int>S,vector<int>P,vector<int>W,vector<int>L){
n = N,s = S,p = P,w = W,l = L;
for(int i = n-1;i>=0;i--){
wins[i] = s[i]+wins[w[i]];
st.insert(s[i]);
}
for(int i = 0;i<n;i++){
int x = i;
for(int j = 1;j<=1000;j++){
mp[i][s[x]] = ls[i].first;
ls[i].first += p[x];
x = l[x];
ls[i].second = x;
if(x==n){ls[i].first = INF;mp[i][s[x]] = INF;break;}
}
}
};
ll simulate(int x,int z){
if(z>=s[x]){
return z+wins[x];
}
else{
bool ok = 0;
for(auto i:st){
if(z+mp[x][i]>=i) ok = 1;
}
if(ok){
while(true){
if(x==n) return z;
else if(z>=s[x]) return z+wins[x];
z += p[x];
x = l[x];
}
}
else{
z += ls[x].first;
x = ls[x].second;
return simulate(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... |