| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 523223 | marat0210 | Dungeons Game (IOI21_dungeons) | C++17 | 0 ms | 0 KiB | 
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 <bits/stdc++.h>
using namespace std;
vector <long long> a, b, win, lose;
void init(long long n, vector <long long> s, vector <long long> p, vector <long long> w, vector <long long> l)
{
    for (int i = 0; i < n; ++i) {
        a.push_back(s[i]);
        b.push_back(p[i]);
        win.push_back(w[i]);
        lose.push_back(l[i]);
    }
}
long long simulate(long long x, long long z)
{
    long long cur = z, d = x;
    while (1) {
        if (d == (long long)a.size()) {
            break;
        }
        if (cur >= a[d]) {
            cur += a[d];
            d = win[d];
        }
        else {
            cur += b[d];
            d = lose[d];
        }
    }
    return cur;
}
