제출 #438986

#제출 시각아이디문제언어결과실행 시간메모리
438986jlallas384던전 (IOI21_dungeons)C++17
24 / 100
7136 ms423688 KiB
#include <bits/stdc++.h> #include "dungeons.h" using namespace std; using ll = long long; vector<vector<pair<int,ll>>> blw,bll; int n; bool st3 = true; vector<vector<pair<int,ll>>> build(vector<int> nxt,vector<int> add){ vector<vector<pair<int,ll>>> bl(n + 1,vector<pair<int,ll>>(30)); for(int i = 0; i < n; i++){ bl[i][0] = {nxt[i],add[i]}; } bl[n][0].first = n; for(int j = 1; j < 30; j++){ for(int i = 0; i <= n; i++){ bl[i][j].first = bl[bl[i][j - 1].first][j - 1].first; bl[i][j].second = bl[i][j - 1].second + bl[bl[i][j - 1].first][j - 1].second; } } return bl; } void init(int _n, vector<int> s, vector<int> p, vector<int> w, vector<int> l){ n = _n; blw = build(w,s); bll = build(l,p); for(int i = 0; i < n; i++){ st3 &= s[i] == s[0]; } } long long simulate(int x, int z){ ll res = z; if(st3){ for(int i = 29; i >= 0; i--){ if(res + bll[x][i].second < blw[0][0].second){ res += bll[x][i].second; x = bll[x][i].first; } } if(res < blw[0][0].second){ res += bll[x][0].second; x = bll[x][0].first; } for(int i = 29; i >= 0; i--){ if(blw[x][i].first != n){ res += blw[x][i].second; x = blw[x][i].first; } } return res + blw[x][0].second; } while(x != n){ if(res < blw[x][0].second){ res += bll[x][0].second; x = bll[x][0].first; }else{ res += blw[x][0].second; x = blw[x][0].first; } } return res; }
#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...