Submission #212723

#TimeUsernameProblemLanguageResultExecution timeMemory
212723spdskatrJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
1097 ms70520 KiB
#include <cstdio> #include <cstdlib> #include <algorithm> #include <vector> #include <queue> #include <unordered_map> #include <unordered_set> using namespace std; int N, M, b[30005], p[30005], seen[30005]; unordered_set<int> doges[30005]; unordered_map<int, int> dists; queue<int> q; int id(int d, int x) { return d * 30001 + x; } void visit(int pos, int d) { seen[pos] = 1; for (int doge : doges[pos]) { dists[id(pos, doge)] = d; q.push(id(pos, doge)); } } int main() { scanf("%d %d", &N, &M); for (int i = 0; i < M; i++) { scanf("%d %d", b+i, p+i); doges[b[i]].insert(p[i]); } visit(b[0], 0); while (q.size()) { int e = q.front(); q.pop(); int loc = e / 30001, power = e % 30001; if (loc == b[1]) { printf("%d\n", dists[e]); return 0; } if (loc - power >= 0) { int pos = loc - power; int d = power; if (!seen[pos]) { visit(pos, dists[e] + 1); } if (dists.find(id(pos, d)) == dists.end()) { dists[id(pos, d)] = dists[e] + 1; q.push(id(pos, d)); } } if (loc + power < N) { int pos = loc + power; int d = power; if (!seen[pos]) { visit(pos, dists[e] + 1); } if (dists.find(id(pos, d)) == dists.end()) { dists[id(pos, d)] = dists[e] + 1; q.push(id(pos, d)); } } } printf("-1\n"); }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", b+i, p+i);
   ~~~~~^~~~~~~~~~~~~~~~~~~
#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...