제출 #566446

#제출 시각아이디문제언어결과실행 시간메모리
566446kartel던전 (IOI21_dungeons)C++17
63 / 100
3559 ms935436 KiB
#include <bits/stdc++.h>
//#include "grader.cpp"
#include "dungeons.h"
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC optimize("-Ofast")
using namespace std;
typedef long long ll;

const int N = 5e4 + 500;
const int log2A = 25;
const int log4N = 18;

int up[N][log4N][log2A];
ll sum[N][log4N][log2A];
ll dp[N][log4N][log2A];
vector <int> s, w;
int n;

void init(int _n, vector <int> _s, vector <int> p, vector <int> _w, vector <int> l) {
    n = _n;
    s = _s; w = _w;
    for (int k = 0; k < log2A; k++) {
        for (int i = 0; i < n; i++) {
            if (s[i] <= (1 << k)) {
                up[i][0][k] = w[i];
                sum[i][0][k] = s[i];
                dp[i][0][k] = -4e18;
            } else {
                up[i][0][k] = l[i];
                sum[i][0][k] = p[i];
                dp[i][0][k] = -s[i];
            }
        }
        for (int st = 1; st < log4N; st++) {
            for (int i = 0; i < n; i++) {
                up[i][st][k] = up[i][st - 1][k];
                sum[i][st][k] = sum[i][st - 1][k];
                dp[i][st][k] = dp[i][st - 1][k];
                for (int j = 1; j < 4; j++) {
                    int to = up[i][st][k];
                    dp[i][st][k] = max(dp[i][st][k], dp[to][st - 1][k] + sum[i][st][k]);
                    sum[i][st][k] += sum[to][st - 1][k];
                    up[i][st][k] = up[to][st - 1][k];
                }
            }
        }
    }
}

ll simulate(int x, int start) {
    ll z = start;

    for (int k = 0; k < log2A && x != n; k++) {
        if (z >= (1 << (k + 1)) && k + 1 < log2A) {
            continue;
        }
        for (int j = log4N - 1; j >= 0 && x != n; j--) {
            for (int p = 0; p < 4 && x != n; p++) {
                if (z + dp[x][j][k] < 0) {
                    z += sum[x][j][k];
                    x = up[x][j][k];
                } else {
                    break;
                }
            }
        }
        if (x == n) {
            break;
        }
        z += s[x];
        x = w[x];
    }
//    assert(x == n);
    return z;
}

/*

3 2
2 6 9
3 1 2
2 2 3
1 0 1
0 1
2 3

*/
#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...