Submission #442827

# Submission time Handle Problem Language Result Execution time Memory
442827 2021-07-09T08:05:52 Z SorahISA Dungeons Game (IOI21_dungeons) C++17
25 / 100
326 ms 326120 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 = 24 + 1;
const int maxlvl = 7 + 1;
const int INF = INT_MAX;

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

vector<int> dep(maxn);

int anc[maxlvl][lgmx][maxn], sum[maxlvl][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), U.eb(x);
    for (auto &x : _P) P.eb(x);
    for (auto &x : _W) W.eb(x);
    for (auto &x : _L) L.eb(x);
    S.eb(0), U.eb(INF), P.eb(0), W.eb(N), L.eb(N);
    
    sort(ALL(U));
    U.resize(unique(ALL(U)) - begin(U));
    tot_lvl = U.size();
    
    memset(anc, 0x00, sizeof(anc));
    memset(sum, 0x00, sizeof(sum));
    
    for (int i = N-1; i >= 0; --i) dep[i] = dep[W[i]] + S[i];
    
    for (int lvl = 0; lvl < tot_lvl; ++lvl) {
        
        /// Assume you have strength in [U_{lvl-1}, U_{lvl}) ///
        
        for (int i = 0; i <= N; ++i) {
            anc[lvl][0][i] = S[i] < U[lvl] ? W[i] : L[i];
            sum[lvl][0][i] = S[i] < U[lvl] ? S[i] : P[i];
        }
        
        for (int lay = 1; lay < lgmx; ++lay) {
            for (int i = 0; i <= N; ++i) {
                int par = anc[lvl][lay-1][i];
                anc[lvl][lay][i] = anc[lvl][lay-1][par];
                sum[lvl][lay][i] = sum[lvl][lay-1][i] + sum[lvl][lay-1][par];
            }
        }
        
    }
}

int simulate(int32_t now, int32_t _Z) {
    int Z = _Z;
    for (int lvl = 0; lvl < tot_lvl; ++lvl) {
        for (int lay = lgmx-1; lay >= 0; --lay) {
            if (Z + sum[lvl][lay][now] < U[lvl]) {
                Z += sum[lvl][lay][now];
                now = anc[lvl][lay][now];
            }
        }
        // cerr << "(lvl, Z, now): " << lvl << "," << Z << "," << now << "\n";
        if (Z >= S[now]) Z += S[now], now = W[now];
        else             Z += P[now], now = L[now];
        // cerr << "(lvl, Z, now): " << lvl << "," << Z << "," << now << "\n";
    }
    return Z + dep[now];
}
# Verdict Execution time Memory Grader output
1 Correct 71 ms 157152 KB Output is correct
2 Runtime error 238 ms 318556 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 235 ms 318884 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 73 ms 157272 KB Output is correct
2 Correct 160 ms 161592 KB Output is correct
3 Correct 204 ms 161616 KB Output is correct
4 Correct 154 ms 161604 KB Output is correct
5 Correct 157 ms 161808 KB Output is correct
6 Correct 174 ms 161600 KB Output is correct
7 Correct 167 ms 161612 KB Output is correct
8 Correct 157 ms 161580 KB Output is correct
9 Correct 155 ms 161664 KB Output is correct
10 Correct 153 ms 161580 KB Output is correct
11 Correct 145 ms 161616 KB Output is correct
12 Correct 242 ms 161616 KB Output is correct
13 Correct 204 ms 161620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 157272 KB Output is correct
2 Correct 160 ms 161592 KB Output is correct
3 Correct 204 ms 161616 KB Output is correct
4 Correct 154 ms 161604 KB Output is correct
5 Correct 157 ms 161808 KB Output is correct
6 Correct 174 ms 161600 KB Output is correct
7 Correct 167 ms 161612 KB Output is correct
8 Correct 157 ms 161580 KB Output is correct
9 Correct 155 ms 161664 KB Output is correct
10 Correct 153 ms 161580 KB Output is correct
11 Correct 145 ms 161616 KB Output is correct
12 Correct 242 ms 161616 KB Output is correct
13 Correct 204 ms 161620 KB Output is correct
14 Correct 75 ms 157276 KB Output is correct
15 Correct 221 ms 161616 KB Output is correct
16 Correct 238 ms 161620 KB Output is correct
17 Correct 278 ms 161704 KB Output is correct
18 Correct 318 ms 161612 KB Output is correct
19 Correct 265 ms 161612 KB Output is correct
20 Correct 235 ms 161684 KB Output is correct
21 Correct 274 ms 161692 KB Output is correct
22 Correct 172 ms 161684 KB Output is correct
23 Correct 219 ms 161744 KB Output is correct
24 Correct 326 ms 161588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 157272 KB Output is correct
2 Correct 160 ms 161592 KB Output is correct
3 Correct 204 ms 161616 KB Output is correct
4 Correct 154 ms 161604 KB Output is correct
5 Correct 157 ms 161808 KB Output is correct
6 Correct 174 ms 161600 KB Output is correct
7 Correct 167 ms 161612 KB Output is correct
8 Correct 157 ms 161580 KB Output is correct
9 Correct 155 ms 161664 KB Output is correct
10 Correct 153 ms 161580 KB Output is correct
11 Correct 145 ms 161616 KB Output is correct
12 Correct 242 ms 161616 KB Output is correct
13 Correct 204 ms 161620 KB Output is correct
14 Correct 75 ms 157276 KB Output is correct
15 Correct 221 ms 161616 KB Output is correct
16 Correct 238 ms 161620 KB Output is correct
17 Correct 278 ms 161704 KB Output is correct
18 Correct 318 ms 161612 KB Output is correct
19 Correct 265 ms 161612 KB Output is correct
20 Correct 235 ms 161684 KB Output is correct
21 Correct 274 ms 161692 KB Output is correct
22 Correct 172 ms 161684 KB Output is correct
23 Correct 219 ms 161744 KB Output is correct
24 Correct 326 ms 161588 KB Output is correct
25 Runtime error 296 ms 326120 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 235 ms 318884 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -