Submission #443100

#TimeUsernameProblemLanguageResultExecution timeMemory
443100ltf0501던전 (IOI21_dungeons)C++17
11 / 100
7093 ms218852 KiB
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
 
const int kN = 4e5 + 10;
const int kC = 25;
// subtask 3
int n;
vector<int> s, p, w, l;
long long suf[kN];
int climb[kC][kN], MAX;
long long max_pow[kC][kN], gained_pow[kC][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]], MAX = max(MAX, s[i]);
  for(int i = 0; i < n; i++) {
    climb[0][i] = l[i];
    max_pow[0][i] = s[i] - 1;
    gained_pow[0][i] = p[i];
  }
  climb[0][n] = n;
 
  for(int j = 1; j < kC; 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;
  int cnt = 0;
  while(x < n && res < int(1e7)) {
    for(int j = kC - 1; j >= 0; j--) {
      if(res > max_pow[j][x]) continue;
      res += gained_pow[j][x], x = climb[j][x];
    }
    cnt++;
    if(x == n) break;
    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...