Submission #623499

#TimeUsernameProblemLanguageResultExecution timeMemory
623499MohamedFaresNebiliDungeons Game (IOI21_dungeons)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

            using namespace std;

            int N, D[50005], A[50005][30], B[50005][30];
            vector<int> S, P, W, L;
            vector<int> rev[50005];
            bool sameS = 1;

            long long solve(int i, int k) {
                if(i == N) return k;
                if(k >= S[i]) return solve(W[i], k + S[i]);
                return solve(L[i], k + P[i]);
            }
            void dfs(int v, int p) {
                for(auto u : rev[v]) {
                    D[u] = D[v] + S[0];
                    dfs(u, v);
                }
            }

            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 l = 0; l < N; l++) {
                    A[l][0] = L[l], B[l][0] = P[l];
                    sameS &= (S[l] == S[0]);
                    rev[W[l]].push_back(l);
                }

                A[N][0] = N;

                for(int l = 0; l <= N; l++)
                    for(int i = 1; i < 30; i++) {
                        A[l][i] = A[A[l][i - 1]][i - 1];
                        B[l][i] = B[l][i - 1] + B[A[l][i - 1]][i - 1];
                    }

                dfs(N, N);
            }

            using ll = long long;

            long long simulate(ll x, ll z) {
                if(!sameS) return solve(x, z);

                if(z >= S[0]) return z + D[x];

                ll res = z;
                for(int l = 25; l >= 0; l--)
                    if(res + B[x][l] < S[0]) {
                        res += B[x][l];
                        x = A[x][l];
                    }
                res += P[x]; x = L[x];
                return res + D[x];
            }

Compilation message (stderr)

/usr/bin/ld: /tmp/ccfpNu0O.o: in function `main':
grader.cpp:(.text.startup+0x440): undefined reference to `simulate(int, int)'
collect2: error: ld returned 1 exit status