이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
#include "dungeons.h"
const int maxn = 4e5+10;
int nn;
ll ss[maxn],pp[maxn],ww[maxn],lr[maxn];
vector <int> val;
ll ans[maxn];
int st[5][24][maxn];
ll gain[5][24][maxn];
void gen(int id,int x) {
rep(i,0,nn) st[id][0][i] = x>=ss[i]?ww[i]:lr[i], gain[id][0][i] = x>=ss[i]?ss[i]:pp[i];
rep(i,1,16) rep(j,0,nn) {
if (st[id][i-1][j]==-1) continue;
st[id][i][j] = st[id][i-1][st[id][i-1][j]];
gain[id][i][j] = gain[id][i-1][j] + gain[id][i-1][st[id][i-1][j]];
}
}
void init(int N, std::vector<int> S, std::vector<int> P, std::vector<int> W, std::vector<int> L) {
memset(st,-1,sizeof(st));
memset(gain,inf,sizeof(gain));
nn = N;
rep(i,0,nn) ss[i] = S[i], pp[i] = P[i], ww[i] = W[i], lr[i] = L[i],val.pb(ss[i]);
sort(ALL(val));
val.erase(unique(ALL(val)),val.end());reverse(ALL(val));
ans[nn] = 0;
for (int i=nn-1;i>=0;i--) ans[i] = ss[i] + ans[ww[i]];
int hi = 0;
for (int i = SZ(val)-1;i>=0;i--) gen(i,hi),hi = val[i];
return;
}
long long simulate(int x, int z) {
vector <int> valcur = val;
ll ret = z;
while (!valcur.empty()) {
while (!valcur.empty() and ret >= valcur.back()) valcur.pop_back();
if (valcur.empty()) break;
int goal = valcur.back();
int id = SZ(valcur)-1;
for (int i=15;i>=0;i--) if (ret + gain[id][i][x] < goal) {
ret += gain[id][i][x];
x = st[id][i][x];
}
//debug(ret),debug(x);
//check whether next step alrd reach goal
if (x==nn) return ret;
ll rett = ret;
if (ret >= ss[x]) rett = ret + ss[x];
else rett = ret + pp[x];
x = ret>=ss[x]? ww[x]:lr[x];
ret = rett;
assert(ret>=goal);
valcur.pop_back();
// debug(ret);debug(x);
}
// debug(ans[x]);
ret += ans[x];
return ret;
}
# | 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... |