Submission #755037

#TimeUsernameProblemLanguageResultExecution timeMemory
755037Rafi22Dungeons Game (IOI21_dungeons)C++17
11 / 100
7045 ms1029728 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define st first #define nd second #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define ll long long ll mod=1000000007; int inf=1000000007; ll infl=1000000000000000007; const int N=50007,K=25; int g[K][K][N]; int mx[K][K][N]; ll sum[K][K][N]; vector<int>S,P,W,L; int n; void init(int nn,vector<int>s,vector<int>p,vector<int>w,vector<int>l) { n=nn; s.pb(0); p.pb(0); w.pb(n); l.pb(n); S=s,P=p,W=w;L=l; for(int j=0;j<K;j++) { for(int i=0;i<=n;i++) { if(s[i]<(1<<j)) { g[j][0][i]=w[i]; sum[j][0][i]=s[i]; mx[j][0][i]=-inf; } else { g[j][0][i]=l[i]; sum[j][0][i]=p[i]; mx[j][0][i]=-s[i]; } } for(int l=1;l<K;l++) { for(int i=0;i<=n;i++) { int x=g[j][l-1][i]; g[j][l][i]=g[j][l-1][x]; sum[j][l][i]=sum[j][l-1][i]+sum[j][l-1][x]; mx[j][l][i]=max(mx[j][l-1][i],(int)min((ll)inf,sum[j][l-1][i]+mx[j][l-1][x])); } } } } int cnt=0; ll simulate(int x,int z) { ll a=z; int j=0; while(x!=n) { while(j<24&&a>=(1LL<<(j+1))) j++; cnt++; for(int l=K-1;l>=0;l--) { if(g[j][l][x]==n||(mx[j][l][x]!=-inf&&a+mx[j][l][x]>=0)) continue; a+=sum[j][l][x]; x=g[j][l][x]; } if(a>=S[x]) { a+=S[x]; x=W[x]; } else { a+=P[x]; x=L[x]; } while(j<24&&a>=(1LL<<(j+1))) j++; } return a; } /*int main() { freopen("inn.txt","r",stdin); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,q; cin>>n>>q; vector<int>sa(n),pa(n),wa(n),la(n); for(int i=0;i<n;i++) cin>>sa[i]; for(int i=0;i<n;i++) cin>>pa[i]; for(int i=0;i<n;i++) cin>>wa[i]; for(int i=0;i<n;i++) cin>>la[i]; init(n,sa,pa,wa,la); while(q--) { int a,b; cin>>a>>b; simulate(a,b); } return 0; }*/
#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...