Submission #601012

#TimeUsernameProblemLanguageResultExecution timeMemory
601012Valaki2Dungeons Game (IOI21_dungeons)C++17
13 / 100
239 ms33368 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; #define n N #define s S #define p P #define w W #define l L #define int long long #define pb push_back const int logn = 31; int n; vector<int> win_str, lose_str, win_pos, lose_pos; int k; vector<vector<int> > lift_str; vector<vector<int> > lift_pos; vector<int> cost; void solve() { k = win_str[0]; lift_str = lift_pos = vector<vector<int> > (1 + n, vector<int> (logn, 0)); for(int i = 0; i <= n; i++) { lift_str[i][0] = lose_str[i]; lift_pos[i][0] = lose_pos[i]; } for(int j = 1; j < logn; j++) { for(int i = 0; i <= n; i++) { lift_str[i][j] = lift_str[i][j - 1] + lift_str[lift_pos[i][j - 1]][j - 1]; lift_pos[i][j] = lift_pos[lift_pos[i][j - 1]][j - 1]; } } cost.assign(1 + n, 0); for(int i = n - 1; i >= 0; i--) { cost[i] = win_str[i] + cost[win_pos[i]]; } } int query(int pos, int strength) { if(strength >= k) { return strength + cost[pos]; } for(int j = logn - 1; j >= 0; j--) { if(strength + lift_str[pos][j] < k) { strength += lift_str[pos][j]; pos = lift_pos[pos][j]; } } strength += lift_str[pos][0]; pos = lift_pos[pos][0]; return strength + cost[pos]; } #undef n #undef s #undef p #undef w #undef l void init(signed n, vector<signed> s, vector<signed> p, vector<signed> w, vector<signed> l) { N = n; win_str = lose_str = win_pos = lose_pos = (vector<int> (n + 1, 0)); for(int i = 0; i < n; i++) { win_str[i] = s[i]; lose_str[i] = p[i]; win_pos[i] = w[i]; lose_pos[i] = l[i]; } win_str[n] = 0; lose_str[n] = 0; win_pos[n] = n; lose_pos[n] = n; solve(); } int simulate(signed x, signed z) { return query(x, 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...