This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "dungeons.h"
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))
#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)
using namespace std;
#define ll long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#ifdef wiwihorz
#define print(a...) cerr << "Line " << __LINE__ << ": ", kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() {cerr << endl;}
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
int N, K = 6, sz, lg;
ll cur;
vector<ll> P;
vector<int> S, W;
vector<vector<int>> to[20];
vector<vector<ll>> ge[20], lim[20];
void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) {
N = n, sz = 0, lg = 20, cur = 1, S = s, W = w;
while(cur < 1e7) sz ++, cur = cur * K;
P.assign(sz + 2, 1), P[sz + 1] = INF;
rep(i, 1, sz) P[i] = P[i - 1] * K;
rep(seg, 0, sz) {
int L = P[seg];
to[seg].assign(lg + 1, vector<int>(n + 1, n));
ge[seg].assign(lg + 1, vector<ll>(n + 1, 0ll));
lim[seg].assign(lg + 1, vector<ll>(n + 1, INF));
rep(i, 0, n - 1) {
if(s[i] < L) {
to[seg][0][i] = w[i];
ge[seg][0][i] = s[i];
lim[seg][0][i] = INF;
}
else {
to[seg][0][i] = l[i];
ge[seg][0][i] = p[i];
lim[seg][0][i] = s[i];
}
}
rep(i, 1, lg) rep(j, 0, n) {
to[seg][i][j] = to[seg][i - 1][to[seg][i - 1][j]];
ge[seg][i][j] = ge[seg][i - 1][j] + ge[seg][i - 1][to[seg][i - 1][j]];
lim[seg][i][j] = min(lim[seg][i - 1][j],
lim[seg][i - 1][to[seg][i - 1][j]] - ge[seg][i - 1][j]);
}
}
return;
}
pair<int, ll> go(int id, int x, ll z) {
rrep(i, 0, lg) {
if(lim[id][i][x] > z) {
z += ge[id][i][x];
x = to[id][i][x];
}
}
if(x == N) return {x, z};
if(z >= S[x]) z += S[x], x = W[x];
else z += ge[id][0][x], x = to[id][0][x];
return {x, z};
}
ll simulate(int x, int z) {
ll cost = z;
rep(i, 0, sz) {
while(cost < P[i + 1]) {
tie(x, cost) = go(i, x, cost);
if(x == N) return cost;
}
}
assert(x == N);
return cost;
}
Compilation message (stderr)
dungeons.cpp:5: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
5 | #pragma loop-opt(on)
|
dungeons.cpp:25:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
25 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
dungeons.cpp:25:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
25 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |