Submission #678715

#TimeUsernameProblemLanguageResultExecution timeMemory
678715qwerasdfzxclJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1099 ms87484 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; constexpr int INF = 1e9+100; struct my_bitset{ unsigned long long bit[500]; bool find(int x){return bit[x/64]&(1LL<<(x&63));} void insert(int x){bit[x/64] |= (1LL<<(x&63));} }; int dist[30030], visited[30030]; set<int> st[30030]; vector<int> a[30030]; struct Vertex{ int s, p; Vertex(){} Vertex(int _s, int _p): s(_s), p(_p) {} //bool operator < (const Vertex &V) const{return d > V.d;} }; int main(){ int n, m, s, e; scanf("%d %d", &n, &m); for (int i=1;i<=m;i++){ int x, p; scanf("%d %d", &x, &p); ++x; a[x].push_back(p); if (i==1) s = x; if (i==2) e = x; } fill(dist+1, dist+n+1, INF); fill(visited+1, visited+n+1, 0); dist[s] = 0; for (int i=1;i<=n;i++){ sort(a[i].begin(), a[i].end()); a[i].erase(unique(a[i].begin(), a[i].end()), a[i].end()); } stack<Vertex, vector<Vertex>> pq[2]; pq[0].emplace(s, 0); int d = 0; while(true){ if (pq[d&1].empty() && pq[(d+1)&1].empty()) break; if (pq[d&1].empty()) {d++; continue;} auto [s, p] = pq[d&1].top(); pq[d&1].pop(); dist[s] = min(dist[s], d); if (p){ if (st[s].find(p)!=st[s].end()) continue; st[s].insert(p); if (s-p > 0) pq[(d+1)&1].emplace(s-p, p); if (s+p <= n) pq[(d+1)&1].emplace(s+p, p); } if (!visited[s]){ visited[s] = 1; for (auto &p2:a[s]){ st[s].insert(p2); if (s-p2 > 0) pq[(d+1)&1].emplace(s-p2, p2); if (s+p2 <= n) pq[(d+1)&1].emplace(s+p2, p2); } } } if (dist[e]==INF) printf("-1\n"); else printf("%d\n", dist[e]); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%d %d", &x, &p);
      |         ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:20:40: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   20 |     Vertex(int _s, int _p): s(_s), p(_p) {}
      |                                        ^
skyscraper.cpp:25:15: note: 's' was declared here
   25 |     int n, m, s, e;
      |               ^
skyscraper.cpp:73:15: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
   73 |     if (dist[e]==INF) printf("-1\n");
      |         ~~~~~~^
#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...