Submission #1053517

#TimeUsernameProblemLanguageResultExecution timeMemory
1053517ZicrusDungeons Game (IOI21_dungeons)C++17
62 / 100
7078 ms1568928 KiB
#include <bits/stdc++.h> #include "dungeons.h" using namespace std; typedef long long ll; ll n; vector<int> s1, p, w, l; vector<ll> s; vector<vector<vector<pair<ll, ll>>>> jmp; vector<vector<pair<ll, ll>>> jmp1; vector<vector<ll>> jmpCheck; vector<ll> dp; bool sub3or4 = true; void init1(int n1, vector<int> s11, vector<int> p1, vector<int> w1, vector<int> l1) { n = n1; s1 = s11; p = p1; w = w1; l = l1; jmp1 = vector<vector<pair<ll, ll>>>(n, vector<pair<ll, ll>>(30)); jmpCheck = vector<vector<ll>>(n, vector<ll>(30)); for (int i = 0; i < n; i++) { jmp1[i][0] = {s1[i], w[i]}; if (jmp1[i][0].second == n) jmp1[i][0].first = 1ll << 31ll; jmpCheck[i][0] = s1[i]; } for (int j = 1; j < 30; j++) { for (int i = 0; i < n; i++) { if (jmp1[i][j-1].second == n) { jmp1[i][j] = {1ll << 31ll, n}; jmpCheck[i][j] = 1ll << 31ll; continue; } else if (jmp1[jmp1[i][j-1].second][j-1].second == n) { jmp1[i][j] = {1ll << 31ll, n}; jmpCheck[i][j] = 1ll << 31ll; continue; } else { jmp1[i][j] = {jmp1[jmp1[i][j-1].second][j-1].first + jmp1[i][j-1].first, jmp1[jmp1[i][j-1].second][j-1].second}; } // jmpCheck jmpCheck[i][j] = max(jmpCheck[jmp1[i][j-1].second][j-1] - jmp1[i][j-1].first, jmpCheck[i][j-1]); } } } ll simulate1(int x1, int z1) { ll i = x1, z = z1; if (i == n) return z; while (z < s1[i]) { z += p[i]; i = l[i]; } while (i < n) { for (int j = 30-1; j >= 0; j--) { if (z >= jmpCheck[i][j] && jmp1[i][j].second < n) { z += jmp1[i][j].first; i = jmp1[i][j].second; } } if (z >= s1[i]) { z += s1[i]; i = w[i]; } while (i < n && z < s1[i]) { z += p[i]; i = l[i]; } } return z; } void init(int n1, vector<int> s11, vector<int> p1, vector<int> w1, vector<int> l1) { n = n1; p = p1; w = w1; l = l1; s1 = s11; vector<int> s22 = s11; s.clear(); jmp.clear(); sort(s22.begin(), s22.end()); ll prev = -1; for (int i = 0; i < n; i++) { if (s22[i] != prev) { jmp.push_back(vector<vector<pair<ll, ll>>>(n, vector<pair<ll, ll>>(30))); s.push_back(s22[i]); prev = s22[i]; if (s.size() > 5) { sub3or4 = false; return init1(n1, s11, p1, w1, l1); } } } for (int h = 0; h < s.size(); h++) { for (int i = 0; i < n; i++) { pair<ll, ll> win = {s1[i], w[i]}; pair<ll, ll> lose = {p[i], l[i]}; jmp[h][i][0] = (h > 0 && s1[i] <= s[h-1]) ? win : lose; if (jmp[h][i][0].second == n) jmp[h][i][0].first = 1ll << 31ll; } } for (int h = 0; h < s.size(); h++) { for (int j = 1; j < 30; j++) { for (int i = 0; i < n; i++) { if (jmp[h][i][j-1].second == n) { jmp[h][i][j] = {1ll << 31ll, n}; continue; } if (jmp[h][jmp[h][i][j-1].second][j-1].second == n) { jmp[h][i][j] = {1ll << 31ll, n}; continue; } jmp[h][i][j] = {jmp[h][jmp[h][i][j-1].second][j-1].first + jmp[h][i][j-1].first, jmp[h][jmp[h][i][j-1].second][j-1].second}; } } } dp = vector<ll>(n+1); dp[n] = 0; for (int i = n-1; i >= 0; i--) { dp[i] = s1[i] + dp[w[i]]; } } ll simulate(int x1, int z1) { if (!sub3or4) return simulate1(x1, z1); ll i = x1, z = z1; if (i == n || z >= s.back()) return z + dp[i]; ll h = 0; while (z < s.back() && i < n) { while (z >= s[h]) h++; for (int j = 30-1; j >= 0; j--) { if (z + jmp[h][i][j].first < s[h]) { z += jmp[h][i][j].first; i = jmp[h][i][j].second; } } if (z < s[h]) { bool win = h > 0 && s1[i] <= s[h-1]; z += win ? s1[i] : p[i]; i = win ? w[i] : l[i]; } } z += dp[i]; return z; }

Compilation message (stderr)

dungeons.cpp: In function 'void init(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
dungeons.cpp:94:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for (int h = 0; h < s.size(); h++) {
      |                     ~~^~~~~~~~~~
dungeons.cpp:102:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |     for (int h = 0; h < s.size(); h++) {
      |                     ~~^~~~~~~~~~
#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...