제출 #437122

#제출 시각아이디문제언어결과실행 시간메모리
437122jeroenodb던전 (IOI21_dungeons)C++17
37 / 100
7044 ms114872 KiB
#ifndef GRADER #include "dungeons.h" #endif #include "bits/stdc++.h" using namespace std; #define all(x) begin(x),end(x) template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; } #define debug(a) cerr << "(" << #a << ": " << a << ")\n"; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pi; const int mxN = 4e5+10, oo = 1e8; int jmp[mxN][20]; bitset<mxN> mx[20]; ll sm[mxN][20]; // int jump(int a, int k) { // int D = max(0,d[a]-k); // while(d[a]>D) { // if(d[jmp[a]]>=D) a = jmp[a]; // else a = par[a]; // } // return a; // } static int N; const int B = 7000; vi S,P,W,L; void init(int n, vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) { S=s,P=p,W=w,L=l; N=n; jmp[n][0]=n; mx[0][n]=true; for(int j=0;j<n;++j) { if(s[j]>=B) { jmp[j][0] = l[j], sm[j][0]=p[j]; } else jmp[j][0] = w[j], sm[j][0] = s[j]; mx[0][j] = s[j]>=B; } for(int i=1;i<20;++i) { for(int j=0;j<=n;++j) { jmp[j][i] = jmp[jmp[j][i-1]][i-1]; mx[i][j] = mx[i-1][j] or mx[i-1][jmp[j][i-1]]; sm[j][i] = sm[j][i-1]+sm[jmp[j][i-1]][i-1]; } } } long long mysimulate(int x, ll z) { int n = N; while(z<B) { if(x==n) return z; if(z>=S[x]) { z+=S[x]; x=W[x]; } else { z+=P[x]; x=L[x]; } } // find next x: S[x]>z, can only happen log times // what if P[x] is very small? while(x!=n) { for(int i=19;i>=0;--i) { if(!mx[i][x]) { z+=sm[x][i]; x=jmp[x][i]; } } if(x==n) return z; if(z>=S[x]) { z+=S[x]; x=W[x]; } else { z+=P[x]; x=L[x]; } } return z; } long long simulate(int x, int z) { return mysimulate(x,z); }
#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...