Submission #761516

#TimeUsernameProblemLanguageResultExecution timeMemory
761516caganyanmazDungeons Game (IOI21_dungeons)C++17
0 / 100
7028 ms724 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; constexpr static int SIZE = 400001; constexpr static int LOG_SIZE = 20; int win_next[SIZE][LOG_SIZE]; int64_t win_gain[SIZE][LOG_SIZE]; int64_t win_max[SIZE][LOG_SIZE]; int n; vector<int> s; vector<int> l; void init(int nn, vector<int> ss, vector<int> p, vector<int> w, vector<int> ll) { n = nn; l = ll; s = ss; for (int i = 0; i < n; i++) assert(s[i] == p[i]); w.pb(n); s.pb(0); for (int i = 0; i < n; i++) { win_next[i][0] = w[i]; win_max[i][0] = win_gain[i][0] = s[i]; } for (int i = 1; i < LOG_SIZE; i++) { for (int j = 0; j < n; j++) { win_next[j][i] = win_next[win_next[j][i-1]][i-1]; win_gain[j][i] = win_gain[j][i-1] + win_gain[win_next[j][i-1]][i-1]; win_max[j][i] = max(win_max[j][i-1], win_max[win_next[j][i-1]][i-1] - win_gain[j][i-1]); } } } int64_t simulate(int x, int zz) { int64_t z = zz; while (x != n) { int _next = LOG_SIZE-1; while (_next >= 0 && win_max[x][_next] > z) _next--; if (_next >= 0) { z += win_gain[x][_next]; x = win_next[x][_next]; } if (x != n && s[x] > z) { z += s[x]; x = l[x]; } } return z; }
#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...