Submission #1285247

#TimeUsernameProblemLanguageResultExecution timeMemory
1285247FaggiDungeons Game (IOI21_dungeons)C++20
11 / 100
7140 ms434964 KiB
#include <bits/stdc++.h> #define ll long long #define sz(x) int(x.size()) #define forn(i, n) for (i = 0; i < n; i++) #define all(x) x.begin(), x.end() #define pb push_back #define mp make_pair #define fr first #define se second using namespace std; const int MAXN = 5e4 + 1; const int LOG = 20; ll ma[MAXN][LOG], up2[MAXN][LOG], sum2[MAXN][LOG]; ll up3[25][MAXN][LOG], sum3[25][MAXN][LOG]; vector<int> S, P, W, L, dif; int N; void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) { ll pot=1; for(ll i=0; i<25; i++) { dif.pb(pot); pot=pot*2; } s.pb(0); p.pb(0); w.pb(n); l.pb(n); ll i, j; N = n; S = s; P = p; W = w; L = l; for (i = 0; i <= n; i++) { up2[i][0] = w[i]; ma[i][0] = s[i]; sum2[i][0] = s[i]; for (j = 0; j < sz(dif); j++) { ll x, y; if(s[i]<dif[j]) { x=w[i]; y=s[i]; } else { x=l[i]; y=p[i]; } up3[j][i][0]=x; sum3[j][i][0]=y; } } for (i = 1; i < LOG; i++) { for (j = 0; j <= n; j++) { up2[j][i] = up2[up2[j][i - 1]][i - 1]; sum2[j][i] = sum2[j][i - 1] + sum2[up2[j][i - 1]][i - 1]; ma[j][i] = max(ma[j][i - 1], ma[up2[j][i - 1]][i - 1]); for (ll k = 0; k < sz(dif); k++) { up3[k][j][i]=up3[k][up3[k][j][i-1]][i-1]; sum3[k][j][i]=sum3[k][j][i-1]+sum3[k][up3[k][j][i-1]][i-1]; } } } return; } long long simulate(int x, int z) { ll act = z, i, ult, pos=0; while (x != N) { if (1ll * S[x] <= act) { ll aum = 0; for (i = LOG - 1; i >= 0; i--) { if (ma[x][i] <= act) { aum += sum2[x][i]; x = up2[x][i]; } } act += aum; } else { while(pos<sz(dif)&&dif[pos]<=act) pos++; for(i=LOG-1; i>=0; i--) { if(sum3[pos][x][i]+act<dif[pos]) { act+=sum3[pos][x][i]; x=up3[pos][x][i]; } } if(S[x]<=act) { act=act+S[x]; x=W[x]; } else { act=act+P[x]; x=L[x]; } } } return act; }
#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...