Submission #1011247

#TimeUsernameProblemLanguageResultExecution timeMemory
1011247mindiyakDungeons Game (IOI21_dungeons)C++17
0 / 100
1 ms604 KiB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops") #include "dungeons.h" #include <bits/stdc++.h> #include <string> #include <iostream> #include <cmath> #include <numeric> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef pair<int, int> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<vector<int>> vvi; typedef vector<vector<ll>> vvl; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; #define FOR(i, a, b) for (int i = a; i < (b); i++) #define F0R(i, a) for (int i = 0; i < (a); i++) #define FORd(i, a, b) for (int i = (b)-1; i >= a; i--) #define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto &a : x) #define uid(a, b) uniform_int_distribution<int>(a, b)(rng) #define len(x) (int)(x).size() #define mp make_pair #define pb push_back #define F first #define nl endl #define S second #define lb lower_bound #define ub upper_bound #define aint(x) x.begin(), x.end() #define raint(x) x.rbegin(), x.rend() #define ins insert const int MOD = 1000000007; vi S,P,W,L,x; vl dist; vvl lost_pos,lost_hp; int N; void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) { S = s; P = p; W = w; L = l; N = n; dist = vl(n+1,-1); dist[n] = 0; lost_pos = vvl(n,vl(log2(n)+1,0)); lost_hp = vvl(n,vl(log2(n)+1,0)); for(int i = n-1;i>=0;i--){ dist[i] = dist[W[i]] + 1; } FOR(i,0,n){ lost_pos[i][0] = L[i]; lost_hp[i][0] = P[i]; } FOR(i,1,log2(n)){ FOR(j,0,n){ lost_pos[j][i] = L[lost_pos[j][i-1]]; lost_hp[j][i] = P[lost_pos[j][i-1]] + lost_hp[j][i-1]; } } // cout << "###############" << endl; // FOR(i,0,log2(n)){ // FOR(j,0,n){ // cout << lost_pos[j][i] << " "; // }cout << endl; // }cout << endl; // FOR(i,0,log2(n)){ // FOR(j,0,n){ // cout << lost_hp[j][i] << " "; // }cout << endl; // }cout << endl; // cout << "###############" << endl; } long long simulate(int x, int z) { // cout << "1 " << x << " " << z << endl; if(x == N)return z; if(z < S[x]){ int pos = upper_bound(lost_hp[x].begin(),lost_hp[x].end(),z) - lost_hp[x].begin(); if(pos == 0)return simulate(lost_pos[x][0],z+lost_hp[x][0]); return simulate(lost_pos[x][pos-1],z+lost_hp[x][pos-1]); } return z+S[x]*(dist[x]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...