Submission #852134

#TimeUsernameProblemLanguageResultExecution timeMemory
852134alex_2008Dungeons Game (IOI21_dungeons)C++17
Compilation error
0 ms0 KiB
#include "dungeons.h" #include <bits/stdc++.h> #define mindiff first #define pos second.first #define strength second.second using namespace std; const int N = 4e5 + 10; const int M = 10000001; const int INF = 1e9 + 10; pair<int, pair<int, int>> dp[N][24][15]; long long NN; vector <int> ss, pp, ww, ll; long long nxt[N]; int lg2[M]; void init(int n, const vector<int>& s, const vector<int>& p, const vector<int>& w, const vector<int>& l) { lg2[1] = 0; for (int i = 2; i < M; i++) { lg2[i] = lg2[i / 2] + 1; } NN = n; s.push_back(0); p.push_back(0); w.push_back(n); l.push_back(n); ss = s; nxt[n] = 0; for (int i = n - 1; i >= 0; i--) { nxt[i] = s[i] + nxt[w[i]]; } pp = p; ww = w; ll = l; for (int k = 0; k < 15; k++) { for (int i = 0; i <= n; i++) { for (int j = 0; j < 24; j++) { if (k == 0) { dp[i][j][k].pos = ((1 << j) >= s[i]) ? w[i] : l[i]; dp[i][j][k].strength = ((1 << j) >= s[i]) ? s[i] : p[i]; dp[i][j][k].mindiff = ((1 << j) < s[i]) ? s[i] : INF; } else { int q = 2, p = dp[i][j][k - 1].pos, sm = 0; while (q--) { p = dp[p][j][k - 1].pos; } dp[i][j][k].pos = p; dp[i][j][k].strength = dp[i][j][k - 1].strength; q = 2; p = dp[i][j][k - 1].pos; while (q--) { dp[i][j][k].strength += dp[p][j][k - 1].strength; dp[i][j][k].strength = min(INF, dp[i][j][k].strength); p = dp[p][j][k - 1].pos; } dp[i][j][k].mindiff = dp[i][j][k - 1].mindiff; q = 2; p = dp[i][j][k - 1].pos; sm = dp[i][j][k - 1].strength; while (q--) { dp[i][j][k].mindiff = min(dp[i][j][k].mindiff, dp[p][j][k - 1].mindiff - sm); sm = min(sm + dp[p][j][k - 1].strength, INF); p = dp[p][j][k - 1].pos; } } } } } } long long simulate(int xx, int zz) { long long x = xx, z = zz; while (1) { if (z >= 10000000) { z += nxt[x]; return z; } int v = lg2[z]; for (int k = 14; k >= 0; k--) { if (dp[x][v][k].pos == NN || dp[x][v][k].mindiff <= z || (z + dp[x][v][k].strength >= 10000000) || lg2[z + dp[x][v][k].strength] > v) continue; z += dp[x][v][k].strength; x = dp[x][v][k].pos; k++; } if (z >= ss[x]) { z += ss[x]; x = ww[x]; } else { z += pp[x]; x = ll[x]; } if (x == NN) return z; } return 0; } //int main() { // init(3, { 2, 6, 9 }, { 3, 1, 2 }, { 2, 2, 3 }, { 1, 0, 1 }); // cout << simulate(0, 1) << "\n"; // cout << simulate(2, 3) << "\n"; //}

Compilation message (stderr)

dungeons.cpp: In function 'void init(int, const std::vector<int>&, const std::vector<int>&, const std::vector<int>&, const std::vector<int>&)':
dungeons.cpp:21:15: error: passing 'const std::vector<int>' as 'this' argument discards qualifiers [-fpermissive]
   21 |  s.push_back(0);
      |               ^
In file included from /usr/include/c++/10/vector:67,
                 from dungeons.h:1,
                 from dungeons.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1203:7: note:   in call to 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
dungeons.cpp:22:15: error: passing 'const std::vector<int>' as 'this' argument discards qualifiers [-fpermissive]
   22 |  p.push_back(0);
      |               ^
In file included from /usr/include/c++/10/vector:67,
                 from dungeons.h:1,
                 from dungeons.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1203:7: note:   in call to 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
dungeons.cpp:23:15: error: passing 'const std::vector<int>' as 'this' argument discards qualifiers [-fpermissive]
   23 |  w.push_back(n);
      |               ^
In file included from /usr/include/c++/10/vector:67,
                 from dungeons.h:1,
                 from dungeons.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note:   in call to 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
dungeons.cpp:24:15: error: passing 'const std::vector<int>' as 'this' argument discards qualifiers [-fpermissive]
   24 |  l.push_back(n);
      |               ^
In file included from /usr/include/c++/10/vector:67,
                 from dungeons.h:1,
                 from dungeons.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note:   in call to 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~