Submission #443071

# Submission time Handle Problem Language Result Execution time Memory
443071 2021-07-09T15:21:26 Z SorahISA Dungeons Game (IOI21_dungeons) C++17
0 / 100
85 ms 37612 KB
#include "dungeons.h"
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define int long long
// #define double long double
using pii = pair<int, int>;
template<typename T>
using Prior = std::priority_queue<T>;
template<typename T>
using prior = std::priority_queue<T, vector<T>, greater<T>>;

#define X first
#define Y second
#define eb emplace_back
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)

namespace {

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

// const int maxn = 4E5 + 5;
const int maxn = 5E4 + 5;
// const int lgmx = 19;
const int lgmx = 17;

int N;
vector<int> S, P, W, L;

int win_anc[lgmx][maxn], win_max_val[lgmx][maxn], win_sum_str[lgmx][maxn];
int los_anc[lgmx][maxn], los_sum_str[lgmx][maxn];

} /// end of namespace

void init(int32_t _N, vector<int32_t> _S, vector<int32_t> _P, vector<int32_t> _W, vector<int32_t> _L) {
    N = _N;
    for (auto &x : _S) S.eb(x);
    for (auto &x : _P) P.eb(x);
    for (auto &x : _W) W.eb(x);
    for (auto &x : _L) L.eb(x);
    
    memset(win_anc, 0x00, sizeof(win_anc));
    memset(win_max_val, 0x00, sizeof(win_max_val));
    memset(win_sum_str, 0x00, sizeof(win_sum_str));
    memset(los_anc, 0x00, sizeof(los_anc));
    memset(los_sum_str, 0x00, sizeof(los_sum_str));
    
    for (int i = 0; i < N; ++i) {
        win_anc[0][i] = W[i];
        win_max_val[0][i] = S[i];
        win_sum_str[0][i] = S[i];
        los_anc[0][i] = L[i];
        los_sum_str[0][i] = P[i];
    }
    win_anc[0][N] = los_anc[0][N] = N;
    
    for (int lay = 1; lay < lgmx; ++lay) {
        for (int i = 0; i <= N; ++i) {
            int win_par = win_anc[lay-1][i];
            win_anc[lay][i] = win_anc[lay-1][win_par];
            win_max_val[lay][i] = max(win_max_val[lay-1][i], win_max_val[lay-1][win_par]);
            win_sum_str[lay][i] = win_sum_str[lay-1][i] + win_sum_str[lay-1][win_par];
            int los_par = los_anc[lay-1][i];
            los_anc[lay][i] = los_anc[lay-1][los_par];
            los_sum_str[lay][i] = los_sum_str[lay-1][i] + los_sum_str[lay-1][los_par];
        }
    }
}

int simulate(int32_t now, int32_t _Z) {
    /// s[i] = s[j] ///
    int Z = _Z;
    for (int lay = lgmx-1; lay >= 0 and now != N; --lay) {
        if (Z + los_sum_str[lay][now] < S[0]) {
            Z += los_sum_str[lay][now];
            now = los_anc[lay][now];
        }
        // cerr << "(Z, now): " << Z << "," << now << "\n";
    }
    if (Z < S[0] and now != N) Z += P[now], now = L[now];
    if (now == N) return Z;
    return Z + win_sum_str[lgmx-1][now];
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 33576 KB Output is correct
2 Incorrect 17 ms 33452 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 33632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 33612 KB Output is correct
2 Correct 82 ms 37580 KB Output is correct
3 Correct 83 ms 37576 KB Output is correct
4 Correct 76 ms 37576 KB Output is correct
5 Correct 75 ms 37612 KB Output is correct
6 Incorrect 85 ms 37596 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 33612 KB Output is correct
2 Correct 82 ms 37580 KB Output is correct
3 Correct 83 ms 37576 KB Output is correct
4 Correct 76 ms 37576 KB Output is correct
5 Correct 75 ms 37612 KB Output is correct
6 Incorrect 85 ms 37596 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 33612 KB Output is correct
2 Correct 82 ms 37580 KB Output is correct
3 Correct 83 ms 37576 KB Output is correct
4 Correct 76 ms 37576 KB Output is correct
5 Correct 75 ms 37612 KB Output is correct
6 Incorrect 85 ms 37596 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 33632 KB Output isn't correct
2 Halted 0 ms 0 KB -