제출 #609055

#제출 시각아이디문제언어결과실행 시간메모리
609055asdfasdfasdfasdf던전 (IOI21_dungeons)C++17
100 / 100
2166 ms542828 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; #define MAX 444444 int N; vector<int> S,P,win,lose; vector<int> v[MAX]; const int INF=1e9; int Next[8][25][MAX]; int Sum[8][25][MAX]; int Value[8][25][MAX]; long long dp[MAX]; void init(int n,vector<int> s,vector<int> p,vector<int> w,vector<int> l) { tie(N,S,P,win,lose)=make_tuple(n,s,p,w,l); for(int i=n-1;i>=0;i--) dp[i]=dp[w[i]]+s[i]; for(int i=0;i<8;i++) { for(int j=0;j<n;j++) { int L=(1<<(3*i)); if(s[j]<L) { Next[i][0][j]=w[j]; Sum[i][0][j]=s[j]; Value[i][0][j]=INF; } else { Next[i][0][j]=l[j]; Sum[i][0][j]=p[j]; Value[i][0][j]=s[j]; } } Next[i][0][n]=n; Sum[i][0][n]=INF; Value[i][0][n]=INF; for(int j=1;j<3*i+3;j++) { for(int k=0;k<=n;k++) { Next[i][j][k]=Next[i][j-1][Next[i][j-1][k]]; Sum[i][j][k]=Sum[i][j-1][k]+Sum[i][j-1][Next[i][j-1][k]]; Sum[i][j][k]=min(Sum[i][j][k],INF); Value[i][j][k]=min(Value[i][j-1][k],Value[i][j-1][Next[i][j-1][k]]-Sum[i][j-1][k]); Value[i][j][k]=max(Value[i][j][k],0); } } } return; } long long simulate(int x, int z) { long long Z=z; for(int i=0;i<8;i++) { while(Z<(1<<(3*i+3))) { for(int j=3*i+2;j>=0;j--) { if(Next[i][j][x]!=N && Z+Sum[i][j][x]<(1<<(3*i+3)) && Value[i][j][x]>Z) { Z+=Sum[i][j][x]; x=Next[i][j][x]; } } if(x!=N && Z<(1<<(3*i+3)) && (S[x]>Z || S[x]<(1<<(2*i)))) { Z+=Sum[i][0][x]; x=Next[i][0][x]; } if(x==N) break; if(S[x]<=Z) { Z+=S[x]; x=win[x]; } if(x==N) break; } } return Z+dp[x]; }
#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...