Submission #793958

#TimeUsernameProblemLanguageResultExecution timeMemory
793958mathematikDungeons Game (IOI21_dungeons)C++17
Compilation error
0 ms0 KiB
#include "dungeons.h" #include <bits/stdc++.h> #define ll long long using namespace std; int binary[25][100000][25][3];//index, +, max excluded int safe_add(int a, int b) { if (a > INT_MAX - b) return INT_MAX; return a + b; } int safe_sub(int a, int b) { return max(a - b, 0LL); } int N; void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) { s.push_back(0); p.push_back(0); w.push_back(n); l.push_back(n); n++; N = n; for (int range = 0; range < 25; range++) { ll r = 1 << range; for (int i = 0; i < n; i++) { if (s[i] <= r) { binary[range][i][0][0] = w[i]; binary[range][i][0][1] = s[i]; binary[range][i][0][2] = LLONG_MAX; } else { binary[range][i][0][0] = l[i]; binary[range][i][0][1] = p[i]; binary[range][i][0][2] = s[i]; } } for (int i = 1; i < 25; i++) { for (int ind = 0; ind < n; ind++) { int pointer = binary[range][ind][i - 1][0]; binary[range][ind][i][0] = binary[range][pointer][i - 1][0]; binary[range][ind][i][1] = safe_add(binary[range][ind][i - 1][1], binary[range][pointer][i - 1][1]); binary[range][ind][i][2] = min(binary[range][ind][i - 1][2], safe_sub(binary[range][pointer][i - 1][2], binary[range][ind][i - 1][1])); } } } } long long simulate(int x, int z) { ll t = z; for (int r = 0; r <= 24; r++) { for (int s = 24; s >= 0; s--) { while (binary[r][x][s][2] > t && x != N - 1 && binary[r][x][s][1] != INT_MAX) { t += binary[r][x][s][1]; x = binary[r][x][s][0]; } } } return t; }

Compilation message (stderr)

dungeons.cpp: In function 'int safe_sub(int, int)':
dungeons.cpp:16:24: error: no matching function for call to 'max(int, long long int)'
   16 |   return max(a - b, 0LL);
      |                        ^
In file included from /usr/include/c++/10/vector:60,
                 from dungeons.h:1,
                 from dungeons.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
dungeons.cpp:16:24: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   16 |   return max(a - b, 0LL);
      |                        ^
In file included from /usr/include/c++/10/vector:60,
                 from dungeons.h:1,
                 from dungeons.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
dungeons.cpp:16:24: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   16 |   return max(a - b, 0LL);
      |                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from dungeons.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
dungeons.cpp:16:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   16 |   return max(a - b, 0LL);
      |                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from dungeons.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
dungeons.cpp:16:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   16 |   return max(a - b, 0LL);
      |                        ^
dungeons.cpp: In function 'void init(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
dungeons.cpp:39:30: warning: overflow in conversion from 'long long int' to 'int' changes value from '9223372036854775807' to '-1' [-Woverflow]
   39 |     binary[range][i][0][2] = LLONG_MAX;
      |                              ^~~~~~~~~