Submission #615479

#TimeUsernameProblemLanguageResultExecution timeMemory
615479MadokaMagicaFanDungeons Game (IOI21_dungeons)C++17
50 / 100
7047 ms455696 KiB
#include "bits/stdc++.h" using namespace std; using ll = long long; const ll inf = 1e9; using vi = vector<int>; using ai = array<ll, 2>; #define sz(v) ((int)v.size()) #define pb push_back #define pry cout << "YES\n" #define prn cout << "NO\n" #define endl '\n' #define fst first #define scn second /* #define ONPC */ const int K = 27; vector<array<array<ll, 3>, 27>> j; vector<array<ai, 27>> f; vector<ll> d; vi s, p, w, l; int n; void init(int _n, vi _s, vi _p, vi _w, vi _l) { n = _n; s = _s; p = _p; w = _w; l = _l; j.assign(n+1,{{}}); f.assign(n+1,{{}}); d.assign(n+1, 0); s.pb(0); p.pb(0); l.pb(n); w.pb(n); f[n][0] = {n,0}; j[n][0] = {n,0,0}; for (int i = n-1; i >= 0; --i) { d[i] = d[w[i]] + s[i]; f[i][0] = {w[i], d[i]+s[i]}; j[i][0] = {l[i], p[i], s[l[i]] - p[i]}; } for (int k = 1; k < K; ++k) { for (int i = 0; i <= n; ++i) { f[i][k][0] = f[f[i][k-1][0]][k-1][0]; f[i][k][1] = max(f[i][k-1][1], f[f[i][k-1][0]][k-1][1]); j[i][k][0] = j[j[i][k-1][0]][k-1][0]; j[i][k][1] = j[i][k-1][1] + j[j[i][k-1][0]][k-1][1]; j[i][k][2] = min(j[i][k-1][2], j[j[i][k-1][0]][k-1][2]-j[i][k-1][1]); } } return; } ll simulate(int x, int _z) { ll z = _z; while (x < n) { /* cout << x << ' ' << z << ' ' << s[x] << endl; */ if (z >= s[x]) { for (int k = K-1; k >= 0; --k) { if (z + d[x] >= f[x][k][1]) { z += d[x]; x = f[x][k][0]; z -= d[x]; } } /* z += s[x]; */ /* x = w[x]; */ } else { for (int k = K-1; k >= 0; --k) { if (z < j[x][k][2]) { z += j[x][k][1]; x = j[x][k][0]; } } z += p[x]; x = l[x]; } } assert(x == n); return z; } #ifdef ONPC void solve() { int n, q; cin >> n >> q; vector<int> s(n), p(n), w(n) ,l(n); for (int i = 0; i < n; ++i) cin >> s[i]; for (int i = 0; i < n; ++i) cin >> p[i]; for (int i = 0; i < n; ++i) cin >> w[i]; for (int i = 0; i < n; ++i) cin >> l[i]; init(n,s,p,w,l); int z, x; while (q--) { cin >> x >> z; cout << simulate(x,z) << endl; } } int32_t main(int argc, char **argv) { if (argc >= 2) { freopen(argv[1], "r", stdin); } else ios_base::sync_with_stdio(0);cin.tie(0); int t = 1; /* cin >> t; */ while(t--) solve(); } #endif
#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...