Submission #110199

#TimeUsernameProblemLanguageResultExecution timeMemory
110199SamAndJakarta Skyscrapers (APIO15_skyscraper)C++17
100 / 100
857 ms226132 KiB
#include <bits/stdc++.h> using namespace std; const int N = 30004; struct ban { int x, p; int d; ban(){} ban(int x, int p, int d) { this->x = x; this->p = p; this->d = d; } }; int n, m; int b[N], p[N]; vector<int> a[N]; bool c[N][N]; int bfs() { queue<ban> q; for (int i = 0; i < a[b[0]].size(); ++i) { if (!c[b[0]][a[b[0]][i]]) { c[b[0]][a[b[0]][i]] = true; q.push(ban(b[0], a[b[0]][i], 0)); } } while (!q.empty()) { ban t; t = q.front(); q.pop(); if (t.x == b[1]) return t.d; if (t.x + t.p < n) { if (!c[t.x + t.p][t.p]) { c[t.x + t.p][t.p] = true; q.push(ban(t.x + t.p, t.p, t.d + 1)); } for (int i = 0; i < a[t.x + t.p].size(); ++i) { ban h(t.x + t.p, a[t.x + t.p][i], t.d + 1); if (!c[h.x][h.p]) { c[h.x][h.p] = true; q.push(h); } } } if (t.x - t.p >= 0) { if (!c[t.x - t.p][t.p]) { c[t.x - t.p][t.p] = true; q.push(ban(t.x - t.p, t.p, t.d + 1)); } for (int i = 0; i < a[t.x - t.p].size(); ++i) { ban h(t.x - t.p, a[t.x - t.p][i], t.d + 1); if (!c[h.x][h.p]) { c[h.x][h.p] = true; q.push(h); } } } } return -1; } int main() { cin >> n >> m; for (int i = 0; i < m; ++i) { cin >> b[i] >> p[i]; a[b[i]].push_back(p[i]); } cout << bfs() << endl; return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int bfs()':
skyscraper.cpp:27:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a[b[0]].size(); ++i)
                     ~~^~~~~~~~~~~~~~~~
skyscraper.cpp:49:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i = 0; i < a[t.x + t.p].size(); ++i)
                             ~~^~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:66:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i = 0; i < a[t.x - t.p].size(); ++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...