This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 10;
const int K = 40;
const int N = 50500;
int n, m;
int s[N];
int p[N];
int w[N];
int l[N];
int us[M];
int dp1[M][K][N];
ll dp2[M][K][N];
void init(int n, vector<int> S, vector<int> P, vector<int> W, vector<int> L) {
::n = n;
copy(S.begin(), S.end(), s);
copy(P.begin(), P.end(), p);
copy(W.begin(), W.end(), w);
copy(L.begin(), L.end(), l);
sort(S.begin(), S.end());
S.erase(unique(S.begin(), S.end()), S.end());
S.insert(S.begin(), 0);
copy(S.begin(), S.end(), us);
m = S.size();
w[n] = l[n] = n;
for (int r = 0; r < m; r++) {
for (int i = 0; i <= n; i++) {
if (S[r] < s[i]) {
dp1[r][0][i] = l[i];
dp2[r][0][i] = p[i];
} else {
dp1[r][0][i] = w[i];
dp2[r][0][i] = s[i];
}
}
for (int j = 1; j < K; j++) {
for (int i = 0; i <= n; i++) {
dp1[r][j][i] = dp1[r][j - 1][dp1[r][j - 1][i]];
dp2[r][j][i] = dp2[r][j - 1][i] + dp2[r][j - 1][dp1[r][j - 1][i]];
}
}
}
}
ll simulate(int i, int z) {
ll x = z;
for (int r = 0; r < m; r++) {
for (int j = K - 1; ~j; --j) {
if (r + 1 == m || x + dp2[r][j][i] < us[r + 1]) {
x += dp2[r][j][i];
i = dp1[r][j][i];
}
if (x < us[r + 1]) {
x += dp2[r][0][i];
i = dp1[r][0][i];
}
}
}
return x;
}
# | 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... |