Submission #443024

#TimeUsernameProblemLanguageResultExecution timeMemory
443024ltf0501Dungeons Game (IOI21_dungeons)C++17
50 / 100
7085 ms415700 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; const int kN = 4e5 + 10; const int kC = 25; // subtask 3 int n; vector<int> s, p, w, l; long long suf[kN]; int climb[2][kC][kN], MAX; // 0: win, 1: lose long long max_pow[2][kC][kN], gained_pow[2][kC][kN]; void init(int _n, vector<int> _s, vector<int> _p, vector<int> _w, vector<int> _l) { n = _n, s = _s, p = _p, w = _w, l = _l; for(int i = n - 1; i >= 0; i--) suf[i] = s[i] + suf[w[i]], MAX = max(MAX, s[i]); for(int i = 0; i < n; i++) { climb[0][0][i] = w[i]; climb[1][0][i] = l[i]; max_pow[0][0][i] = s[i]; max_pow[1][0][i] = s[i] - 1; gained_pow[0][0][i] = s[i]; gained_pow[1][0][i] = p[i]; } climb[0][0][n] = n; climb[1][0][n] = n; for(int j = 1; j < kC; j++) { for(int i = 0; i <= n; i++) { climb[0][j][i] = climb[0][j - 1][climb[0][j - 1][i]]; climb[1][j][i] = climb[1][j - 1][climb[1][j - 1][i]]; max_pow[0][j][i] = max(max_pow[0][j - 1][i], max_pow[0][j - 1][climb[0][j - 1][i]] - gained_pow[0][j - 1][i]); max_pow[1][j][i] = min(max_pow[1][j - 1][i], max_pow[1][j - 1][climb[1][j - 1][i]] - gained_pow[1][j - 1][i]); gained_pow[0][j][i] = gained_pow[0][j - 1][i] + gained_pow[0][j - 1][climb[0][j - 1][i]]; gained_pow[1][j][i] = gained_pow[1][j - 1][i] + gained_pow[1][j - 1][climb[1][j - 1][i]]; } } return; } long long simulate(int x, int z) { long long res = z; int cnt = 0; while(x < n) { cnt++; bool flag = (res < s[x]); for(int j = kC - 1; j >= 0; j--) { auto Check = [&]()->bool { if(flag) return res > max_pow[flag][j][x]; else return res < max_pow[flag][j][x]; }; if(Check()) continue; res += gained_pow[flag][j][x], x = climb[flag][j][x]; } } return res; }
#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...