이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
#define mindiff first
#define pos second.first
#define strength second.second
using namespace std;
const long long N = 4e5 + 10;
const long long M = 10000001;
const int INF = 1e7;
pair<int, pair<int, int>> dp[N][8][13];
long long NN;
vector <long long> ss, pp, ww, ll;
long long nxt[N];
int lg4[M];
bool ch = true;
void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) {
for (int i = 1; i < 4; i++) {
lg4[i] = 0;
}
for (int i = 4; i < M; i++) {
lg4[i] = lg4[i / 4] + 1;
}
NN = n;
s.push_back(0);
p.push_back(0);
w.push_back(n);
l.push_back(n);
for (int i = 0; i <= n; i++) {
ss.push_back(s[i]);
if (w[i] != l[i]) ch = false;
}
nxt[n] = 0;
for (int i = n - 1; i >= 0; i--) {
nxt[i] = s[i] + nxt[w[i]];
}
for (int i = 0; i <= n; i++) {
pp.push_back(p[i]);
}
for (int i = 0; i <= n; i++) {
ww.push_back(w[i]);
}
for (int i = 0; i <= n; i++) {
ll.push_back(l[i]);
}
for (int k = 0; k < 24; k++) {
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= 12; j++) {
if (k == 0) {
dp[i][j][k].pos = ((1 << (2 * j)) >= s[i]) ? w[i] : l[i];
dp[i][j][k].strength = ((1 << (2 * j)) >= s[i]) ? s[i] : p[i];
dp[i][j][k].mindiff = ((1 << (2 * j)) < s[i]) ? s[i] : INF;
}
else {
int p = dp[i][j][k - 1].pos;
dp[i][j][k].pos = dp[p][j][k - 1].pos;
dp[i][j][k].strength = min(INF, dp[i][j][k - 1].strength + dp[p][j][k - 1].strength);
dp[i][j][k].mindiff = max(0, min(dp[i][j][k - 1].mindiff, dp[p][j][k - 1].mindiff - dp[i][j][k - 1].strength));
}
}
}
}
}
long long simulate(int xx, int zz) {
long long x = xx, z = zz;
while (1) {
if (z >= 10000000) {
z += nxt[x];
return z;
}
int v = lg4[z];
for (int k = 23; k >= 0; k--) {
if (dp[x][v][k].pos == N || dp[x][v][k].mindiff <= z || (dp[x][v][k].strength + z >= 10000000) || lg4[dp[x][v][k].strength + z] > v) continue;
z += dp[x][v][k].strength;
x = dp[x][v][k].pos;
}
if (z >= ss[x]) {
z += ss[x];
x = ww[x];
}
else {
z += pp[x];
x = ll[x];
}
if (x == NN) return z;
}
return 0;
}
//int main() {
// init(3, { 2, 6, 9 }, { 3, 1, 2 }, { 2, 2, 3 }, { 1, 0, 1 });
// cout << simulate(0, 1) << "\n";
// cout << simulate(2, 3) << "\n";
//}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |