Submission #800436

#TimeUsernameProblemLanguageResultExecution timeMemory
800436MohamedAliSaidaneDungeons Game (IOI21_dungeons)C++17
37 / 100
7074 ms1789616 KiB
#include <bits/stdc++.h> #include "dungeons.h" using namespace std; typedef vector<int> vi; typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pll; typedef pair<int,int> pii; #define ff first #define ss second #define pb push_back #define all(x) (x).begin(),(x).end() const int nax = 4e5 + 5; const ll INF = 1e7; const int LG = 25; const int LG2 = 9; const int b = 6; int n; vi S, P, W, L; int sp[nax][LG2][LG]; ll mini[nax][LG2][LG]; ll ps[nax][LG2][LG]; ll POW[LG2]; void init(int N, vi s, vi p, vi w, vi l) { n = N, S = s, P = p, W= w, L = l; S.pb(0); W.pb(n); POW[0] = 1ll; for(int i =1; i < LG2; i++) POW[i] = (POW[i - 1] * 1ll * b); for(int i = 0; i <= n; i++) { for(int l = 0; l < LG2; l++) { if(S[i] <= POW[l]) { sp[i][l][0] = W[i]; mini[i][l][0] = INF * 1ll * INF; ps[i][l][0] = S[i]; } else { sp[i][l][0] = L[i]; mini[i][l][0] = S[i]; ps[i][l][0] = P[i]; } } } for(int j = 1; j < LG; j++) { for(int i = 0; i <= n; i++) { for(int l = 0; l < LG2; l++) { sp[i][l][j] = sp[sp[i][l][j - 1]][l][j - 1]; mini[i][l][j] = min(mini[i][l][j - 1], mini[sp[i][l][j - 1]][l][j - 1] - ps[i][l][j - 1]); ps[i][l][j] = ps[i][l][j - 1] + ps[sp[i][l][j - 1]][l][j - 1]; } } } } pair<int,ll> check(int i, ll z) { ll delta = 0ll; int l = 0; while((l < LG2) && POW[l] <= z) l++; l--; if((S[i] > POW[l]) && (S[i] <= z)) return {i, 0ll}; //cout << '\t' << i << ' ' << z << ' ' << l << '\n'; for(int j = LG - 1; j >= 0; j--) { bool cond = (mini[i][l][j] - delta <= z) || (sp[i][l][j] == n); if(!(cond)) { delta += ps[i][l][j]; i = sp[i][l][j]; } } if(z + delta < mini[i][l][0]) { delta += ps[i][l][0]; i = sp[i][l][0]; } return {i, delta}; } ll simulate(int x, int Z) { ll z = Z; while(x != n) { // cout << x << ' ' << z << '\n'; pair<int,ll> u = check(x, z); x = u.ff; z += u.ss; z += S[x]; x = W[x]; } return z; } /* int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); /* int n, q; cin >> n >> q; vi 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); while(q--) { int x, z; cin >> x >> z; cout << simulate(x, z) << '\n'; } init(3, {2, 6, 9}, {3, 1, 2}, {2, 2, 3}, {1, 0, 1}); cout << simulate(0, 1) << '\n'; cout << simulate(2, 3) << '\n'; } */

Compilation message (stderr)

dungeons.cpp:113:5: warning: "/*" within comment [-Wcomment]
  113 |     /*
      |
#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...