Submission #1126536

#TimeUsernameProblemLanguageResultExecution timeMemory
1126536Zbyszek99Dungeons Game (IOI21_dungeons)C++20
11 / 100
355 ms202888 KiB
#include "dungeons.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define ull unsigned long long #define ff first #define ss second #define pii pair<int,int> #define pll pair<long long, long long> #define vi vector<int> #define vl vector<long long> #define pb push_back #define rep(i, b) for(int i = 0; i < (b); ++i) #define rep2(i,a,b) for(int i = a; i <= (b); ++i) #define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c) #define count_bits(x) __builtin_popcountll((x)) #define all(x) (x).begin(),(x).end() #define siz(x) (int)(x).size() #define forall(it,x) for(auto& it:(x)) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; //mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());} //ll rand(ll a, ll b) {return a + (mt() % (b-a+1));} const int INF = 1e9+50; const ll INF_L = 1e18+40; const ll MOD = 1e9+7; int P[16]; struct jump_str { int v; int sum; ll ile; }; jump_str jump[16][400001][16]; int l[400001]; int w[400001]; int win_cost[400001]; int n; jump_str merge_jumps(jump_str s1, jump_str s2) { jump_str ans; ans.v = s2.v; ans.sum = s1.sum + s2.sum; if(ans.sum >= 1e7) ans.sum = 1e7; ans.ile = min(s1.ile,s2.ile - s1.sum); return ans; } pll find_next_lose(int v, ll s, int p) { for(int i = 15; i >= 0; i--) { //cout << v << " " << s << " " << jump[p][v][i].v << " " << jump[p][v][i].ile << " " << jump[p][v][i].sum << " " << i << " " << p << " jump\n"; if(jump[p][v][i].ile > s) { s += jump[p][v][i].sum; v = jump[p][v][i].v; } //cout << v << " " << s << " " << jump[p][v][i].v << " " << jump[p][v][i].ile << " " << jump[p][v][i].sum << " " << i << " jump\n"; if(jump[p][v][i].ile > s) { s += jump[p][v][i].sum; v = jump[p][v][i].v; } } //cout << v << " " << l[v] << " lost\n"; return {w[v],s + win_cost[v]}; } int find_seg(ll x) { rep(i,16) { if(x < P[i]) { return i-1; } } return 15; } void init(int N, vector<int> s, vector<int> p, vector<int> W, vector<int> L) { n = N; rep(i,n) { l[i] = L[i]; w[i] = W[i]; win_cost[i] = s[i]; } w[n] = n; l[n] = n; P[0] = 1; rep2(i,1,15) { P[i] = P[i-1] * 3; } rep(i,16) { rep(v,n) { if(s[v] <= P[i]) { jump[i][v][0] = {w[v],s[v],INF_L}; } else { jump[i][v][0] = {l[v],p[v],s[v]}; } } jump[i][n][0] = {n,0,INF_L}; rep2(j,1,15) { rep(v,n+1) { jump_str new_jump = merge_jumps(jump[i][v][j-1],jump[i][jump[i][v][j-1].v][j-1]); new_jump = merge_jumps(new_jump,jump[i][new_jump.v][j-1]); jump[i][v][j] = new_jump; } } } } ll simulate(int v, int Z) { ll z = Z; while(v != n) { int seg = find_seg(z); //cout << v << " " << z << " " << seg << " jumping\n"; pll nex = find_next_lose(v,z,seg); v = nex.ff; z = nex.ss; //cout << v << " " << z << " " << seg << " jumping\n"; } return z; }
#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...