제출 #443090

#제출 시각아이디문제언어결과실행 시간메모리
443090ltf0501던전 (IOI21_dungeons)C++17
13 / 100
194 ms129328 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; const int kN = 4e5 + 10; const int kC = 25; // subtask 1, 2, 3 int n; vector<int> s, p, w, l; vector<int> uni_s; long long suf[kN]; int climb[5][kC][kN], MAX; // 0: win, 1: lose long long max_pow[5][kC][kN], gained_pow[5][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; w.push_back(n), s.push_back(0); p.push_back(0), l.push_back(0); 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++) uni_s.push_back(s[i]); sort(uni_s.begin(), uni_s.end()); uni_s.resize(unique(uni_s.begin(), uni_s.end()) - uni_s.begin()); int m = int(uni_s.size()); auto get_id = [&](int x) { return int(lower_bound(uni_s.begin(), uni_s.end(), x) - uni_s.begin()); }; for(int i = 0; i <= n; i++) { int id = get_id(s[i]); for(int j = 0; j < m; j++) { if(j >= id) { // dp[j][][] power at least uni_s[j] climb[j][0][i] = w[i]; max_pow[j][0][i] = MAX; gained_pow[j][0][i] = s[i]; } else { climb[j][0][i] = l[i]; max_pow[j][0][i] = s[i] - 1; gained_pow[j][0][i] = p[i]; } } } for(int j = 1; j < kC; j++) { for(int i = 0; i <= n; i++) { for(int o = 0; o < m; o++) { climb[o][j][i] = climb[o][j - 1][climb[o][j - 1][i]]; max_pow[o][j][i] = min(max_pow[o][j - 1][i], max_pow[o][j - 1][climb[o][j - 1][i]] - gained_pow[o][j - 1][i]); gained_pow[o][j][i] = gained_pow[o][j - 1][i] + gained_pow[o][j - 1][climb[o][j - 1][i]]; } } } return; } long long simulate(int x, int z) { long long res = z; while(x < n && res < MAX) { int id = upper_bound(uni_s.begin(), uni_s.end(), res) - uni_s.begin() - 1; //cerr << "id = " << id << '\n'; for(int j = kC - 1; j >= 0; j--) { if(res > max_pow[id][j][x]) continue; res += gained_pow[id][j][x], x = climb[id][j][x]; } //cerr << "x = " << x << ", pow = " << res << '\n'; res += s[x], x = w[x]; } res += suf[x]; //cerr << "Finish\n"; 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...