Submission #786108

#TimeUsernameProblemLanguageResultExecution timeMemory
786108devariaotaJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
26 ms34636 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define ld long double #define fi first #define se second queue<pair<int, int>> q; vector<int> adj[30005]; int dist[2005][2005]; bool vis[2005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; int s, f; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); if (i == 0) s = u; if (i == 1) f = u; } for (int i = 0; i <= 2000; i++) { for (int j = 0; j <= 2000; j++) dist[i][j] = -1; } for (auto x : adj[s]) { q.push({s, x}); dist[s][x] = 0; } vis[s] = 1; while (!q.empty()) { int x = q.front().fi, d = q.front().se; q.pop(); if (x == f) { cout << dist[x][d] << "\n"; return 0; } if (x - d >= 0 and !vis[x - d]) { vis[x - d] = 1; for (auto u : adj[x - d]) { q.push({x - d, u}); dist[x - d][u] = dist[x][d] + 1; } } if (x - d >= 0 and dist[x - d][d] == -1) { q.push({x - d, d}); dist[x - d][d] = dist[x][d] + 1; } if (x + d < n and !vis[x + d]) { vis[x + d] = 1; for (auto u : adj[x + d]) { q.push({x + d, u}); dist[x + d][u] = dist[x][d] + 1; } } if (x + d < n and dist[x + d][d] == -1) { q.push({x + d, d}); dist[x + d][d] = dist[x][d] + 1; } } cout << -1 << "\n"; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:18:9: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   18 |     int s, f;
      |         ^
skyscraper.cpp:37:9: warning: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |         if (x == f) {
      |         ^~
#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...