Submission #1058586

#TimeUsernameProblemLanguageResultExecution timeMemory
1058586pccDungeons Game (IOI21_dungeons)C++17
37 / 100
7021 ms187708 KiB
#include "dungeons.h" #include <vector> #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define fs first #define sc second #define pll pair<ll,ll> const int B = 20; const int mxn = 4e5+10; int par[mxn][B]; ll dp[mxn][B]; ll sum[mxn][B]; ll pref[mxn]; int N; int str[mxn],win[mxn],lose[mxn],cost[mxn]; void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) { memset(par,-1,sizeof(par)); N = n; for(int i = 0;i<N;i++){ str[i] = s[i]; cost[i] = p[i]; win[i] = w[i]; lose[i] = l[i]; } win[N] = lose[N] = N; for(int i = 0;i<B;i++){ par[N][i] = -1; } for(int i = N-1;i>=0;i--){ pref[i] = str[i]+pref[win[i]]; dp[i][0] = str[i]+pref[i]; par[i][0] = win[i]; sum[i][0] = str[i]; for(int j = 1;j<B;j++){ int pre = par[i][j-1]; if(pre == -1)continue; par[i][j] = par[par[i][j-1]][j-1]; dp[i][j] = max(dp[i][j-1],dp[par[i][j-1]][j-1]); sum[i][j] = sum[i][j-1]+sum[par[i][j-1]][j-1]; } } /* cerr<<"PAR: "<<endl;for(int i = 0;i<N;i++){ for(int j = 0;j<B;j++)cerr<<par[i][j]<<' ';cerr<<endl; } cerr<<"DP: "<<endl;for(int i = 0;i<N;i++){ for(int j = 0;j<B;j++)cerr<<dp[i][j]<<' ';cerr<<endl; } cerr<<"SUM: "<<endl;for(int i = 0;i<N;i++){ for(int j = 0;j<B;j++)cerr<<sum[i][j]<<' ';cerr<<endl; } cerr<<"PREF: "<<endl;for(int i = 0;i<=N;i++)cerr<<pref[i]<<' ';cerr<<endl; */ return; } long long simulate(int x, int z) { int now = x; ll val = z; while(now != N){ //cerr<<"CHALLENGE: "<<now<<":"<<val<<endl; for(int i = B-1;i>=0;i--){ int pre = par[now][i]; if(pre == -1)continue; if(val+pref[now]>=dp[now][i]){ val += sum[now][i]; now = par[now][i]; //cerr<<"WIN: "<<now<<','<<i<<' '<<val<<endl; } } //cerr<<"LOST: "<<now<<' '<<val<<endl; val += cost[now]; now = lose[now]; } return val; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...