Submission #1121286

#TimeUsernameProblemLanguageResultExecution timeMemory
1121286mmdrzadaJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1042 ms1956 KiB
#include <iostream> #include <vector> using namespace std; vector<int> g[30005]; int f[30005], da[30005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, h, k; cin >> n >> m; for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; if (i == 1) h = x; if (i == 2) k = x; g[x].push_back(y); } for (int i = 0; i < n; i++) f[i] = 1e9; f[h] = 0; for (int jj = 0; jj < n; jj++) { int p, mi = 1e9; for (int i = 0; i < n; i++) { if (da[i] == 0 && mi > f[i]) { mi = f[i]; p = i; } } if (p == k) break; da[p] = 1; for (int w : g[p]) { int l = 0; for (int j = p - w; j >= 0; j -= w) { f[j] = min(f[j], f[p] + l + 1); l++; } l = 0; for (int j = p + w; j < n; j += w) { f[j] = min(f[j], f[p] + l + 1); l++; } } } if (f[k] == 1e9) cout << -1; else cout << f[k]; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:38:37: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |                 f[j] = min(f[j], f[p] + l + 1);
      |                                  ~~~^
skyscraper.cpp:28:9: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
   28 |         if (p == k) break;
      |         ^~
skyscraper.cpp:19:10: warning: 'h' may be used uninitialized in this function [-Wmaybe-uninitialized]
   19 |     f[h] = 0;
      |     ~~~~~^~~
#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...