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>
#define ll long long
#define pb push_back
using namespace std;
int N;
vector<int>strength,power,win,lose;
vector<int>pre_process;
vector<bool>vis;
int dfs(int node){
if(vis[node])return pre_process[node];
if(node!=N){
vis[node]=1;
pre_process[node]=1+dfs(win[node]);
}
return pre_process[node];
}
void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) {
N=n;
pre_process.resize(n+1,0);
vis.assign(n+1,0);
strength=s;
power=p;
win=w;
lose=l;
for(int i=0;i<n;i++){
if(vis[i])continue;
dfs(i);
}
return;
}
ll simulate(int x, int z) {
// int n=4;
// vector<int>s={6,6,6,6},p={1,2,1,3},w={2,4,3,4},l={1,3,1,0};
// init(n,s,p,w,l);
// // for(int i=0;i<n;i++){
// // cout<<pre_process[i]<<' ';
// // }
ll ans=z;
while(ans<strength[0]){
ans+=power[x];
x=lose[x];
}
ans+=pre_process[x]*strength[0];
return ans;
}
// int main(){
// int n=3,q=2;
// cout<<simulate(1,1);
// // simulate(2,3);
// return 0;
// }
# | 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... |