Submission #622578

#TimeUsernameProblemLanguageResultExecution timeMemory
622578jiahngDungeons Game (IOI21_dungeons)C++17
63 / 100
6075 ms1732396 KiB
#include "dungeons.h" #include <vector> #include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef pair<int32_t, ll> pi; typedef vector <int> vi; typedef vector <pi> vpi; typedef pair<pi, ll> pii; typedef set <ll> si; typedef long double ld; #define f first #define s second #define mp make_pair #define FOR(i,s,e) for(int i=s;i<=int(e);++i) #define DEC(i,s,e) for(int i=s;i>=int(e);--i) #define pb push_back #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) #define aFOR(i,x) for (auto i: x) #define mem(x,i) memset(x,i,sizeof x) #define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define maxn 50010 #define maxb1 61 #define maxb2 20 #define INF (ll)1e18 #define MOD 1000000007 typedef pair <vi, int> pvi; typedef pair <int,pi> ipi; typedef vector <pii> vpii; pi dp[maxn][maxb1][maxb2]; // (ending node, added val) if start at i and do 2^k steps winning if 2^j >= S int mx[maxn][maxb1][maxb2]; // max z for dp[i][j][k] to be accurate int S[maxn], P[maxn], W[maxn], L[maxn]; int N; inline int msb(int x){ return 63 - __builtin_clzl(x); } void init(int32_t n, std::vector<int32_t> s, std::vector<int32_t> p, std::vector<int32_t> w, std::vector<int32_t> l) { N = n; FOR(i,0,N-1){ S[i] = s[i], P[i] = p[i], W[i] = w[i], L[i] = l[i]; } FOR(i,0,N-1) FOR(j,0,maxb1-1){ if ((1LL << j) >= S[i]) dp[i][j][0] = pi(W[i], S[i]); else dp[i][j][0] = pi(L[i], P[i]); if (S[i] > (1LL << j)) mx[i][j][0] = S[i] - 1; else mx[i][j][0] = INF; } FOR(j,0,maxb1-1) dp[N][j][0] = pi(N, 0); FOR(k,1,maxb2-1) FOR(j,0,maxb1-1){ FOR(i,0,N){ dp[i][j][k] = dp[dp[i][j][k-1].f][j][k-1]; dp[i][j][k].s += dp[i][j][k-1].s; mx[i][j][k] = min(mx[i][j][k-1], mx[dp[i][j][k-1].f][j][k-1] - dp[i][j][k-1].s); } } return; } long long simulate(int32_t x, int32_t _z) { ll z = _z; while (1){ //cout << msb(z) << ' '; //cout << x << ' '; int a = msb(z); DEC(k,maxb2-1,0) if (z <= mx[x][msb(z)][k] && dp[x][msb(z)][k].f < N){ pi val = dp[x][msb(z)][k]; z += val.s;; x = val.f; } //cout << x << ' '; //cout << x << ' ' << z << '\n'; if (z >= S[x] && W[x] == N) return z + S[x]; if (z < S[x] && L[x] == N) return z + P[x]; //cout << z << ' '; if (z >= S[x]){ z += S[x]; x = W[x]; }else{ z += P[x]; x = L[x]; } //cout << x << ' '; //cout << zz << ' ' << z << '\n'; //assert(msb(z) >= a+1); } return 0; }

Compilation message (stderr)

dungeons.cpp: In function 'long long int simulate(int32_t, int32_t)':
dungeons.cpp:74:13: warning: unused variable 'a' [-Wunused-variable]
   74 |         int a = msb(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...