Submission #794657

#TimeUsernameProblemLanguageResultExecution timeMemory
794657finn__Dungeons Game (IOI21_dungeons)C++17
89 / 100
7174 ms1479520 KiB
#include <bits/stdc++.h> #include "dungeons.h" using namespace std; constexpr size_t N = 400001, K = 26, L = 9; size_t n; uint32_t f[L][K][N], m[L][K][N]; uint64_t u[L][K][N]; 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 = move(s_); p = move(p_); w = move(w_); l = move(l_); for (size_t k = 0; k < L; ++k) { for (size_t i = 0; i < n; ++i) { if (s[i] < 1ULL << (k * 3)) f[k][0][i] = w[i], u[k][0][i] = s[i], m[k][0][i] = UINT32_MAX; else f[k][0][i] = l[i], u[k][0][i] = p[i], m[k][0][i] = s[i]; } f[k][0][n] = n; u[k][0][n] = 0; m[k][0][n] = UINT32_MAX; for (size_t j = 1; j < K; ++j) for (size_t i = 0; i < n; ++i) { size_t const intermediate = f[k][j - 1][i]; f[k][j][i] = f[k][j - 1][intermediate]; u[k][j][i] = u[k][j - 1][i] + u[k][j - 1][intermediate]; if (intermediate == n) m[k][j][i] = UINT32_MAX; m[k][j][i] = m[k][j - 1][i]; if (m[k][j - 1][intermediate] != UINT32_MAX) m[k][j][i] = min<uint64_t>(m[k][j][i], min<uint64_t>(m[k][j - 1][i], m[k][j - 1][intermediate] - min<uint64_t>(m[k][j - 1][intermediate], u[k][j - 1][i]))); } } } long long simulate(int x, int z) { long long strength = z; while (x != n) { size_t const k = min<size_t>(L - 1, __lg(strength) / 3); for (size_t j = K - 1; j < K; --j) if (m[k][j][x] > strength) { strength += u[k][j][x]; x = f[k][j][x]; break; } if (x != n) { if (strength >= s[x]) { strength += s[x]; x = w[x]; } else { strength += p[x]; x = l[x]; } } } return strength; }

Compilation message (stderr)

dungeons.cpp: In function 'void init(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
dungeons.cpp:26:22: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'long long unsigned int' [-Wsign-compare]
   26 |             if (s[i] < 1ULL << (k * 3))
dungeons.cpp: In function 'long long int simulate(int, int)':
dungeons.cpp:58:14: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     while (x != n)
      |            ~~^~~~
dungeons.cpp:69:15: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         if (x != n)
      |             ~~^~~~
#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...