Submission #623890

#TimeUsernameProblemLanguageResultExecution timeMemory
623890sofapudenDungeons Game (IOI21_dungeons)C++17
36 / 100
5912 ms1217612 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int mxN = 4e5+1; const int M = 9; int b[mxN][M][17]; ll t[mxN][M][17], a[mxN][M][17]; vector<int> s, p, w, l; int n; const ll inf = (1ll<<60); 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 = 0; i < 17; ++i){ b[n][0][i] = n; t[n][0][i] = inf; a[n][0][i] = 0; for(int k = 0; k < n; ++k){ if(s[k] <= (1<<i<<7)){ t[k][0][i] = inf; a[k][0][i] = s[k]; b[k][0][i] = w[k]; } else{ t[k][0][i] = s[k]; a[k][0][i] = p[k]; b[k][0][i] = l[k]; } } for(int j = 1; j < 2*M; ++j){ for(int k = 0; k < n; ++k){ int cur = (j-1)%M; t[k][j%M][i] = (t[b[k][cur][i]][cur][i] == inf ? t[k][cur][i] : min(t[b[k][cur][i]][cur][i] - a[k][cur][i], t[k][cur][i])); a[k][j%M][i] = a[b[k][cur][i]][cur][i] + a[k][cur][i]; b[k][j%M][i] = b[b[k][cur][i]][cur][i]; } } } } ll simulate(int x, int _z) { ll z = _z; while(z <= 64 && x != n) { if(z >= s[x]){ z += s[x]; x = w[x]; } else { z += p[x]; x = l[x]; } } if(x != n){ for(int i = 0; i < 17; ++i){ for(int j = M-1; ~j; --j){ while(x != n && z < t[x][j][i]){ z += a[x][j][i]; x = b[x][j][i]; } } while(x != n && z <= (1<<i<<8)){ if(z >= s[x]){ z += s[x]; x = w[x]; } else { z += p[x]; x = l[x]; } } if(x == n)break; } while(x != n) { if(z >= s[x]){ z += s[x]; x = w[x]; } else { z += p[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...