Submission #1046237

# Submission time Handle Problem Language Result Execution time Memory
1046237 2024-08-06T12:00:30 Z VMaksimoski008 Dungeons Game (IOI21_dungeons) C++17
11 / 100
7000 ms 239660 KB
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int maxn = 4e5 + 5;
const int LOG = 41;
vector<int> S, P, W, L, graph[maxn];
int N, sub3 = 1, up[maxn][LOG], dist[maxn];
ll sum[maxn][LOG];

void dfs(int u) {
    for(int &v : graph[u]) {
        dist[v] = dist[u] + 1;
        dfs(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 i=1; i<N; i++) if(S[i] != S[i-1]) sub3 = 0;
    for(int i=0; i<N; i++) graph[W[i]].push_back(i);
    for(int i=0; i<N; i++) up[i][0] = L[i], sum[i][0] = P[L[i]];
    up[N][0] = N; dfs(N);

    for(int j=1; j<LOG; j++)
        for(int i=0; i<=N; i++) up[i][j] = up[up[i][j-1]][j-1];
    for(int j=1; j<LOG; j++)
        for(int i=0; i<=N; i++) sum[i][j] = sum[i][j-1] + sum[up[i][j-1]][j-1];
	return;
}

long long simulate(int x, int z) {
    if(sub3) {
        if(z >= S[x]) return (ll)z + (ll)dist[x] * S[x];
        ll ans = z + P[x];

        for(int i=LOG-1; i>=0; i--) {
            if(up[x][i] == N) continue;
            if(ans + sum[x][i] < S[x]) {
                ans += sum[x][i];
                x = up[x][i];
            }
        }

        ans += sum[x][0];
        x = up[x][0];

        if(x == N) return ans;
        return ans + (ll)S[x] * dist[x];
    }

    ll ans = z;
    while(x != N) {
        if(z >= S[x]) {
            z += S[x];
            x = W[x];
        } else {
            z += P[x];
            x = L[x];
        }
    }
	return z;
}

Compilation message

dungeons.cpp: In function 'void init(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
dungeons.cpp:33:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   33 |     for(int j=1; j<LOG; j++)
      |     ^~~
dungeons.cpp:35:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   35 |  return;
      |  ^~~~~~
dungeons.cpp: In function 'long long int simulate(int, int)':
dungeons.cpp:58:8: warning: unused variable 'ans' [-Wunused-variable]
   58 |     ll ans = z;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 1 ms 12892 KB Output is correct
3 Correct 3 ms 15196 KB Output is correct
4 Correct 30 ms 40988 KB Output is correct
5 Correct 3 ms 15196 KB Output is correct
6 Correct 31 ms 40912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 15196 KB Output is correct
2 Execution timed out 7094 ms 239660 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 15196 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 15196 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 15196 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 15196 KB Output is correct
2 Execution timed out 7094 ms 239660 KB Time limit exceeded
3 Halted 0 ms 0 KB -