Submission #563238

#TimeUsernameProblemLanguageResultExecution timeMemory
563238hoanghq2004Dungeons Game (IOI21_dungeons)C++17
100 / 100
6597 ms1401408 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include "dungeons.h" using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; const int N = 4e5 + 10; int n; int s[N], p[N], w[N], l[N]; int nxt[N][7][25]; long long dmin[N][7][25]; long long sum[N][7][25]; vector <long long> pivot; void init(int _n, std::vector<int> S, std::vector<int> P, std::vector<int> W, std::vector<int> L) { n = _n; for (int i = 0; i < n; ++i) s[i] = S[i], p[i] = P[i], w[i] = W[i], l[i] = L[i]; for (int i = 0; i < 7; ++i) pivot.push_back(1 << i * 4); pivot.push_back(1e18); for (int b = 0; b + 1 < pivot.size(); ++b) { for (int i = 0; i < n; ++i) { if (s[i] <= pivot[b]) { nxt[i][b][0] = w[i]; dmin[i][b][0] = 1e18; sum[i][b][0] = s[i]; } else { nxt[i][b][0] = l[i]; dmin[i][b][0] = s[i]; sum[i][b][0] = p[i]; } } nxt[n][b][0] = n; for (int lg = 1; lg < 25; ++lg) { for (int i = 0; i <= n; ++i) { nxt[i][b][lg] = nxt[nxt[i][b][lg - 1]][b][lg - 1]; sum[i][b][lg] = sum[i][b][lg - 1] + sum[nxt[i][b][lg - 1]][b][lg - 1]; dmin[i][b][lg] = min(dmin[i][b][lg - 1], dmin[nxt[i][b][lg - 1]][b][lg - 1] - sum[i][b][lg - 1]); } } } } long long simulate(int i, int z) { long long cur = z; int b = 0; while (b + 1 < pivot.size()) { if (cur >= pivot[b + 1]) { ++b; continue; } for (int lg = 24; lg >= 0; --lg) { if (nxt[i][b][lg] == n || dmin[i][b][lg] - cur <= 0) continue; cur += sum[i][b][lg]; i = nxt[i][b][lg]; } if (cur >= s[i]) { cur += s[i]; i = w[i]; } else { cur += p[i]; i = l[i]; } if (i == n) return cur; } return cur; } //int main() { // freopen("test.inp", "r", stdin); // freopen("test.out", "w", stdout); // int n, q; // std::vector<int> s, p, z; // std::vector<int> w, l, x; // std::vector<long long> answer; // // assert(scanf("%d %d", &n, &q) == 2); // s.resize(n); // p.resize(n); // w.resize(n); // l.resize(n); // x.resize(q); // z.resize(q); // answer.resize(q); // // for (int i = 0; i < n; i++) { // assert(scanf("%d", &s[i]) == 1); // } // for (int i = 0; i < n; i++) { // assert(scanf("%d", &p[i]) == 1); // } // for (int i = 0; i < n; i++) { // assert(scanf("%d", &w[i]) == 1); // } // for (int i = 0; i < n; i++) { // assert(scanf("%d", &l[i]) == 1); // } // // // init(n, s, p, w, l); // // for (int i = 0; i < q; i++) { // assert(scanf("%d %d", &x[i], &z[i]) == 2); // answer[i] = simulate(x[i], z[i]); // } // fclose(stdin); // // for (int i = 0; i < q; i++) { // printf("%lld\n", answer[i]); // } // fclose(stdout); // return 0; //}

Compilation message (stderr)

dungeons.cpp: In function 'void init(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
dungeons.cpp:28:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int b = 0; b + 1 < pivot.size(); ++b) {
      |                     ~~~~~~^~~~~~~~~~~~~~
dungeons.cpp: In function 'long long int simulate(int, int)':
dungeons.cpp:54:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     while (b + 1 < pivot.size()) {
      |            ~~~~~~^~~~~~~~~~~~~~
#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...