Submission #846923

#TimeUsernameProblemLanguageResultExecution timeMemory
846923manhlinh1501Jakarta Skyscrapers (APIO15_skyscraper)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int N = 3e4 + 5; const int oo = 1e9; const int SQRT = 175; #define eb emplace_back struct node { int w, u, s; node() { w = u = s = 0; } node(int w, int u, int s) : w(w), u(u), s(s) {} friend bool operator > (node a, node b) { return a.w > b.w; } }; struct data { int to, w, cur; data() { to = w = cur = 0; } data(int to, int w, int cur) : to(to), w(w), cur(cur) {} }; int n, m; int dist[N]; pii a[N]; vector<data> adj[N]; priority_queue<node, vector<node>, greater<node>> Q; void update(int u, int v, int w, int cur) { if(dist[v] > dist[u] + w) { dist[v] = dist[u] + w; Q.emplace(dist[v], v, cur); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 0; i < m; i++) { int u, v; cin >> u >> v; for(int j = 1; j * v <= n or j * v <= u; j++) adj[u].eb(j * v, j, v); a[i] = {u, v}; } for(int i = 0; i < n; i++) dist[i] = oo; dist[a[0].first] = 0; Q.emplace(0, a[0].first, a[0].second); while(!Q.empty()) { node top = Q.top(); Q.pop(); int u = top.u; if(top.w != dist[u]) continue; for(auto [v, w, cur] : adj[u]) { if(u + v <= n) update(u, u + v, w, cur); if(u - v >= 0) update(u, u - v, w, cur); } } cout << (dist[a[1].first] == oo ? -1 : dist[a[1].first]); } /* 5 3 0 2 1 1 4 1 */

Compilation message (stderr)

skyscraper.cpp:38:12: error: template argument 1 is invalid
   38 | vector<data> adj[N];
      |            ^
skyscraper.cpp:38:12: error: template argument 2 is invalid
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:10:12: error: request for member 'emplace_back' in 'adj[u]', which is of non-class type 'int'
   10 | #define eb emplace_back
      |            ^~~~~~~~~~~~
skyscraper.cpp:59:20: note: in expansion of macro 'eb'
   59 |             adj[u].eb(j * v, j, v);
      |                    ^~
skyscraper.cpp:78:37: error: 'begin' was not declared in this scope
   78 |         for(auto [v, w, cur] : adj[u]) {
      |                                     ^
skyscraper.cpp:78:37: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from skyscraper.cpp:1:
/usr/include/c++/10/valarray:1224:5: note:   'std::begin'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from skyscraper.cpp:1:
/usr/include/c++/10/bits/fs_dir.h:549:3: note:   'std::filesystem::__cxx11::begin'
  549 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
skyscraper.cpp:78:37: error: 'end' was not declared in this scope
   78 |         for(auto [v, w, cur] : adj[u]) {
      |                                     ^
skyscraper.cpp:78:37: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from skyscraper.cpp:1:
/usr/include/c++/10/valarray:1244:5: note:   'std::end'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from skyscraper.cpp:1:
/usr/include/c++/10/bits/fs_dir.h:554:3: note:   'std::filesystem::__cxx11::end'
  554 |   end(recursive_directory_iterator) noexcept
      |   ^~~