제출 #442984

#제출 시각아이디문제언어결과실행 시간메모리
442984ltf0501던전 (IOI21_dungeons)C++17
11 / 100
7072 ms178096 KiB
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;

const int kN = 4e5 + 10;
// subtask 3
int n;
vector<int> s, p, w, l;
int suf[kN];
int climb[20][kN];
long long max_pow[20][kN], gained_pow[20][kN];
void init(int _n, vector<int> _s, vector<int> _p, vector<int> _w, vector<int> _l) {
  n = _n, s = _s, p = _p, w = _w, l = _l;
  
  for(int i = n - 1; i >= 0; i--) suf[i] = s[i] + suf[w[i]];
  for(int i = 0; i < n; i++) {
    climb[0][i] = l[i];
    max_pow[0][i] = s[i];
    gained_pow[0][i] = p[i];
  }
  climb[0][n] = n;

  for(int j = 1; j < 20; j++) {
    for(int i = 0; i < n; i++) {
      climb[j][i] = climb[j - 1][climb[j - 1][i]];
      max_pow[j][i] = min(max_pow[j - 1][i], max_pow[j - 1][climb[j - 1][i]] - gained_pow[j - 1][i]);
      gained_pow[j][i] = gained_pow[j - 1][i] + gained_pow[j - 1][climb[j - 1][i]];
    }
  }
	return;
}

long long simulate(int x, int z) {
  long long res = z;
  while(x < n && res < int(1e7)) {
    for(int j = 19; j >= 0; j--) {
      if(res >= max_pow[j][x]) continue;
      res += gained_pow[j][x], x = climb[j][x];
    }
    res += s[x], x = w[x];
  }
  res += suf[x];
  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...