Submission #609379

#TimeUsernameProblemLanguageResultExecution timeMemory
609379FatihSolakDungeons Game (IOI21_dungeons)C++17
62 / 100
7015 ms303580 KiB
#include "dungeons.h" #include <bits/stdc++.h> #define N 400005 #define M 50005 #define K 30 #define X 10 using namespace std; struct node{ int to; long long val; }; struct node2{ int to; long long sum; long long maxi; }; node sp[M][X][K]; node2 sp2[N][K]; vector<int> numbers; int sz; int n; bool subtask4 = 0; bool subtask2 = 1; vector<int> s,p,w,l; void init(int n_, vector<int> s_, vector<int> p_, vector<int> w_, vector<int> l_) { n = n_; s = s_; p = p_; w = w_; l = l_; for(int i = 0;i<n;i++){ subtask2 &= (s[i] == p[i]); numbers.push_back(s[i]); } sort(numbers.begin(),numbers.end()); numbers.resize(unique(numbers.begin(),numbers.end())-numbers.begin()); sz = numbers.size(); if(sz <= 5 && n <= 50000)subtask4 = 1; if(subtask4){ for(int x = 0;x<=sz;x++){ sp[n][x][0].to = n; sp[n][x][0].val = 0; for(int i = 0;i<n;i++){ int num = upper_bound(numbers.begin(),numbers.end(),s[i]) - numbers.begin(); if(num <= x){ sp[i][x][0].to = w[i]; sp[i][x][0].val = s[i]; } else{ sp[i][x][0].to = l[i]; sp[i][x][0].val = p[i]; } } for(int j = 1;j<K;j++){ for(int i = 0;i<=n;i++){ sp[i][x][j].val = sp[i][x][j-1].val + sp[sp[i][x][j-1].to][x][j-1].val; sp[i][x][j].to = sp[sp[i][x][j-1].to][x][j-1].to; } } } } if(subtask2){ for(int i = 0;i<n;i++){ sp2[i][0].to = w[i]; sp2[i][0].sum = s[i]; sp2[i][0].maxi = s[i]; } sp2[n][0].to = n; sp2[n][0].sum = 0; sp2[n][0].maxi = 0; for(int j = 1;j<K;j++){ for(int i = 0;i<=n;i++){ sp2[i][j].to = sp2[sp2[i][j-1].to][j-1].to; sp2[i][j].sum = sp2[i][j-1].sum + sp2[sp2[i][j-1].to][j-1].sum; sp2[i][j].maxi = max(sp2[i][j-1].maxi,sp2[sp2[i][j-1].to][j-1].maxi - sp2[i][j-1].sum); } } } return; } long long simulate(int x, int z) { long long pw = z; int now = upper_bound(numbers.begin(),numbers.end(),pw) - numbers.begin(); if(subtask2){ while(x != n){ for(int i = K-1;i>=0;i--){ if(sp2[x][i].maxi <= pw){ pw += sp2[x][i].sum; x = sp2[x][i].to; } } if(x != n){ pw += p[x]; x = l[x]; } } return pw; } if(subtask4){ while(x != n){ //cout << now << " " << x << " " << pw << endl; if(now == sz){ pw += sp[x][now][K-1].val; x = sp[x][now][K-1].to; assert(x == n); } else{ for(int i = K-1;i>=0;i--){ if(sp[x][now][i].val + pw < numbers[now]){ pw += sp[x][now][i].val; x = sp[x][now][i].to; } } pw += sp[x][now][0].val; x = sp[x][now][0].to; while(now != sz && pw >= numbers[now]) now++; } } return pw; } while(x != n){ if(s[x] <= pw){ pw += s[x]; x = w[x]; } else{ pw += p[x]; x = l[x]; } } return pw; }
#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...