Submission #1162184

#TimeUsernameProblemLanguageResultExecution timeMemory
1162184minhpkJakarta Skyscrapers (APIO15_skyscraper)C++20
Compilation error
0 ms0 KiB
#include "bits/stdc++.h" using namespace std; int a, b; vector<int> z[1000005]; int blocksize; pair<int, int> mark[30005]; struct node { int val, pos, type; bool operator>(const node &other) const { return val > other.val; } }; int base; inline long long encode(int pos, int type) { return (long long) pos * base + type; } unordered_map<long long, int> dist; void dijkstra() { priority_queue<node, vector<node>, greater<node>> q; long long key0 = encode(mark[0].first, mark[0].second); dist[key0] = 0; q.push({0, mark[0].first, mark[0].second}); while (!q.empty()) { node cur = q.top(); q.pop(); int d = cur.val, pos = cur.pos, type = cur.type; long long curKey = encode(pos, type); if (dist[curKey] <= d) continue; if (type == 0) { for (int p : z[pos]) { int newPos = pos + p; if (newPos < a) { long long key = encode(newPos, p); int nd = d + 1; if (!dist.count(key) || dist[key] > nd) { dist[key] = nd; q.push({nd, newPos, p}); } } newPos = pos - p; if (newPos >= 0) { long long key = encode(newPos, p); int nd = d + 1; if (!dist.count(key) || dist[key] > nd) { dist[key] = nd; q.push({nd, newPos, p}); } } } } else { long long key0 = encode(pos, 0); if (!dist.count(key0) || dist[key0] > d) { dist[key0] = d; q.push({d, pos, 0}); } if (type > blocksize) { int step = 1; while (pos + step * type < a) { int newPos = pos + step * type; long long key = encode(newPos, 0); int nd = d + step; if (!dist.count(key) || dist[key] > nd) { dist[key] = nd; q.push({nd, newPos, 0}); } step++; } step = 1; while (pos - step * type >= 0) { int newPos = pos - step * type; long long key = encode(newPos, 0); int nd = d + step; if (!dist.count(key) || dist[key] > nd) { dist[key] = nd; q.push({nd, newPos, 0}); } step++; } } else { int newPos = pos + type; if (newPos < a) { long long key = encode(newPos, type); int nd = d + 1; if (!dist.count(key) || dist[key] > nd) { dist[key] = nd; q.push({nd, newPos, type}); } } newPos = pos - type; if (newPos >= 0) { long long key = encode(newPos, type); int nd = d + 1; if (!dist.count(key) || dist[key] > nd) { dist[key] = nd; q.push({nd, newPos, type}); } } } } } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> a >> b; blocksize = min(a,2*sqrt(a)); base = a + 1; for (int i = 0; i < b; i++){ int x, y; cin >> x >> y; z[x].push_back(y); mark[i] = {x, y}; } if(b == 0){ cout << -1; return 0; } dist.reserve(100000); dijkstra(); long long finalKey = encode(mark[1].first, 0); if(dist.count(finalKey)){ cout << dist[finalKey]; } else { cout << -1; } return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:122:20: error: no matching function for call to 'min(int&, __gnu_cxx::__enable_if<true, double>::__type)'
  122 |     blocksize = min(a,2*sqrt(a));
      |                 ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from skyscraper.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
skyscraper.cpp:122:20: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__enable_if<true, double>::__type' {aka 'double'})
  122 |     blocksize = min(a,2*sqrt(a));
      |                 ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from skyscraper.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
skyscraper.cpp:122:20: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__enable_if<true, double>::__type' {aka 'double'})
  122 |     blocksize = min(a,2*sqrt(a));
      |                 ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from skyscraper.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3449:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3449 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3449:5: note:   template argument deduction/substitution failed:
skyscraper.cpp:122:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  122 |     blocksize = min(a,2*sqrt(a));
      |                 ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from skyscraper.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3455:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3455 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3455:5: note:   template argument deduction/substitution failed:
skyscraper.cpp:122:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  122 |     blocksize = min(a,2*sqrt(a));
      |                 ~~~^~~~~~~~~~~~~