Submission #1040451

#TimeUsernameProblemLanguageResultExecution timeMemory
1040451Alihan_8Dungeons Game (IOI21_dungeons)C++17
0 / 100
50 ms45636 KiB
#include "dungeons.h" #include <vector> #include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define ar array #define pb push_back #define ln '\n' //#define int long long using i64 = long long; template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } const i64 inf = 1e15; vector <int> s, p, w, l; vector <i64> sf; vector <vector<i64>> up, sm; int n; void init(int n_, std::vector<int> s_, std::vector<int> p_, std::vector<int> w_, std::vector<int> l_) { n = n_, s = s_, p = p_, w = w_, l = l_; up.resize(n + 1), sm.resize(n + 1); sf.resize(n + 1); for ( int i = n - 1; i >= 0; i-- ){ sf[i] = sf[w[i]] + 1; } for ( int i = 0; i <= n; i++ ){ up[i].resize(20); sm[i].resize(20); if ( i < n ){ up[i][0] = l[i]; sm[i][0] = p[i]; } } sm[n][0] = inf; up[n][0] = n; for ( int i = 1; i < 20; i++ ){ for ( int j = 0; j <= n; j++ ){ up[j][i] = up[up[j][i - 1]][i - 1]; sm[j][i] = sm[up[j][i - 1]][i - 1] + sm[j][i - 1]; chmin(sm[j][i], inf); } } } long long simulate(int x, int z) { i64 cnt = z; if ( s[0] <= cnt ){ return cnt + sf[x] * 1LL * s[0]; } for ( int i = 19; i >= 0; i-- ){ if ( cnt + sm[x][i] < s[0] ){ cnt += sm[x][i]; x = up[x][i]; } } if ( x < n && cnt < s[0] ){ cnt += sm[x][0]; x = up[x][0]; } assert(cnt >= s[0] || x == n); return cnt + sf[x] * 1LL * s[0]; }
#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...