Submission #1271309

#TimeUsernameProblemLanguageResultExecution timeMemory
1271309nerrrminDungeons Game (IOI21_dungeons)C++20
0 / 100
1 ms580 KiB
#include "dungeons.h" #include <vector> using namespace std; const int maxn = 4e5 + 10; int nn; vector < int > a, b; vector < int > win, lose; int req, jump[maxn][30], collect[maxn][30]; void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) { nn = n; a.resize(n, 0); b.resize(n, 0); req = s[0]; for (int i = 0; i < nn; ++ i) a[i] = s[i]; for (int i = 0; i < nn; ++ i) b[i] = p[i]; win.resize(n, 0); lose.resize(n, 0); for (int i = 0; i < nn; ++ i) win[i] = w[i]; for (int i = 0; i < nn; ++ i) lose[i] = l[i]; for (int i = 0; i < n; ++ i) { jump[i][0] = lose[i]; collect[i][0] = b[i]; } for (int j = 1; j < 30; ++ j) { for (int i = 0; i < n; ++ i) { jump[i][j] = jump[jump[i][j-1]][j-1]; collect[i][j] = collect[i][j-1] + collect[jump[i][j-1]][j-1]; } } } bool check(int start, int s, int x) { long long pos = start, power = s; for (int i = 29; i >= 0; -- i) { if((1 << i) & x) { pos = jump[pos][i]; power += collect[pos][i]; } } return (power >= req); } long long rec(long long pos, long long s) { if(pos == nn)return s; if(s >= a[pos])return rec(win[pos], s+a[pos]); else return rec(lose[pos], s+b[pos]); } long long simulate(int x, int z) { int lt = 0, rt = 1e7, mid, ans = 1e7+1; while(lt <= rt) { mid = (lt + rt)/2; if(check(x, z, mid)) { rt = mid - 1; ans = mid; } else lt = mid + 1; } long long pos = x, power = z; for (int bit = 0; bit < 30; ++ bit) { if((1 << bit) & ans) { pos = jump[pos][bit]; power += collect[pos][bit]; } } return rec(pos, power); }
#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...