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 "dungeons.h"
#include <algorithm>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
//#define int long long
#define ll long long
#define loop(X, N) for(int X = 0; X < (N); X++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef uint64_t u64;
typedef int64_t i64;
int n;
vector<ll> s, p;
vi w, l;
void init(int _n, std::vector<int> _s, std::vector<int> _p, std::vector<int> _w, std::vector<int> _l) {
n = _n;
w = _w;
l = _l;
w.push_back(n);
l.push_back(n);
//set<ll> strengths;
for (int x : _s) {
s.push_back(x);
//strengths.insert(x);
}
for (int x : _p) p.push_back(x);
s.push_back(0);
p.push_back(0);
}
long long simulate(int x, int _z) {
int start = x;
ll z = _z;
while (x != n) {
ll minAlong = LLONG_MAX;
ll sumAlong = 0;
do {
if (z >= s[x]) {
z += s[x];
sumAlong += s[x];
x = w[x];
}
else {
z += p[x];
sumAlong += p[x];
x = l[x];
minAlong = min(minAlong, s[x]);
}
} while (x != start && x != n);
if (x == n)
break;
if (z < minAlong) {
int count = (minAlong - z + sumAlong - 1) / sumAlong;
z += sumAlong * count;
}
}
return z;
}
# | 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... |