Submission #768909

#TimeUsernameProblemLanguageResultExecution timeMemory
768909raysh07Jakarta Skyscrapers (APIO15_skyscraper)C++17
0 / 100
1 ms324 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define INF (int)1e18 #define f first #define s second mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); void Solve() { int n, m; cin >> n >> m; vector <pair<int, int>> a(m); set <int> st[n]; int target; vector <int> d(n, INF); priority_queue <pair<int, int>> pq; for (int i = 0; i < m; i++){ cin >> a[i].f >> a[i].s; if (i == 0) { d[a[i].f] = 0; pq.push({0, a[i].f}); } if (i != 1) st[a[i].f].insert(a[i].s); else target = a[i].f; } vector<vector<pair<int, int>>> adj(n); for (int i = 0; i < n; i++){ for (auto x : st[i]){ for (int j = 1; ; j++){ int go = x * j + i; if (go >= n || st[go].find(x) != st[go].end()) break; adj[i].push_back({go, j}); } for (int j = 1; ; j++){ int go = i - x * j; if (go < 0 || st[go].find(x) != st[go].end()) break; adj[i].push_back({go, j}); } } } while (!pq.empty()){ auto pi = pq.top(); pq.pop(); int u = pi.second; int ds = -pi.first; if (d[u] != ds) continue; for (auto [v, w] : adj[u]){ if (d[v] > d[u] + w){ d[v] = d[u] + w; pq.push({-d[v], v}); } } } // cout << target << "\n"; if (d[target] == INF) cout << -1 << "\n"; else cout << d[target] << "\n"; } int32_t main() { auto begin = std::chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; for(int i = 1; i <= t; i++) { //cout << "Case #" << i << ": "; Solve(); } auto end = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'void Solve()':
skyscraper.cpp:65:17: warning: 'target' may be used uninitialized in this function [-Wmaybe-uninitialized]
   65 |     if (d[target] == INF) cout << -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...