#include "dungeons.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
const i64 inf = 1e15;
const int L = 25;
vector <int> s, p, w, l;
int n;
struct Jump{
vector <vector<i64>> U, S, need, has;
int n, lim;
Jump() {}
void modify(vector <int> p, vector <int> w, int lim_){
n = p.size(); lim = lim_;
S.resize(n + 1);
U.resize(n + 1);
need.resize(n + 1);
has.resize(n + 1);
for ( int i = 0; i <= n; i++ ){
S[i].resize(L);
U[i].resize(L);
need[i].resize(L);
has[i].resize(L);
if ( i == n ) continue;
S[i][0] = w[i];
U[i][0] = p[i];
need[i][0] = s[i];
has[i][0] = (s[i] >= lim);
}
U[n][0] = n;
S[n][0] = inf;
has[n][0] = 1;
for ( int i = 1; i < L; i++ ){
for ( int j = 0; j <= n; j++ ){
U[j][i] = U[U[j][i - 1]][i - 1];
S[j][i] = min(inf, S[j][i - 1] + S[U[j][i - 1]][i - 1]);
need[j][i] = min(need[j][i - 1], need[U[j][i - 1]][i - 1] - S[j][i - 1]);
has[j][i] = has[j][i - 1] | has[U[j][i - 1]][i - 1];
}
}
}
i64 simulate(int &u, i64 z, i64 rq){
for ( int i = L - 1; i >= 0; i-- ){
if ( U[u][i] == n ) continue;
if ( (!has[u][i] || need[u][i] > z) && z + S[u][i] < rq ){
z += S[u][i];
u = U[u][i];
}
}
//~ cout << u << " " << z << ln;
if ( u != n && z < rq ){
if ( s[u] <= z ){
z += s[u];
u = w[u];
} else{
z += p[u];
u = l[u];
}
}
return z;
};
};
vector <Jump> A;
vector <i64> v;
void init(int n_, std::vector<int> s_, std::vector<int> p_, std::vector<int> w_, std::vector<int> l_) {
n = n_, s = s_, p = p_, w = w_, l = l_;
v.pb(inf);
//~ for ( auto &u: s ) v.pb(u);
for ( int i = 0; i <= L; i++ ){
v.pb(1LL << i);
}
sort(all(v));
v.resize(unique(all(v)) - v.begin());
for ( auto &x: v ){
vector <int> fa(n), wh(n);
for ( int i = 0; i < n; i++ ){
if ( s[i] < x ){
fa[i] = w[i];
wh[i] = s[i];
} else{
fa[i] = l[i];
wh[i] = p[i];
}
}
Jump h; h.modify(fa, wh, x);
A.pb(h);
}
}
long long simulate(int x, int Z) {
// subtask #4
i64 z = Z;
for ( int i = 0; i + 2 < (int)v.size(); i++ ){
z = A[i].simulate(x, z, v[i + 1]);
}
z = A.back().simulate(x, z, inf);
assert(x == n);
return z;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
40 ms |
51292 KB |
Output is correct |
4 |
Correct |
1591 ms |
1274400 KB |
Output is correct |
5 |
Incorrect |
49 ms |
51380 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
34 ms |
52304 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
35 ms |
52224 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
35 ms |
52224 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
35 ms |
52224 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
34 ms |
52304 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |