Submission #52654

#TimeUsernameProblemLanguageResultExecution timeMemory
52654evpipisJakarta Skyscrapers (APIO15_skyscraper)C++11
100 / 100
321 ms45132 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair typedef pair<int, int> ii; const int len = 30005, inf = 1e9; int po[len], pos[len], vis[len], dis[len][180][2]; vector<int> vec[len]; //map<int, int> mymap[len]; deque<pair<ii, ii> > deq; int main(){ int n, m, k; scanf("%d %d", &n, &m); k = sqrt(n)+1; for (int i = 0; i < m; i++) scanf("%d %d", &pos[i], &po[i]); for (int i = 0; i < m; i++) vec[pos[i]].pb(po[i]); for (int i = 0; i < n; i++) for (int j = 0; j <= k; j++) dis[i][j][0] = dis[i][j][1] = inf; int ans = -1; deq.pb(mp(mp(0, 0), mp(pos[0], po[0]))); deq.pb(mp(mp(0, 1), mp(pos[0], po[0]))); while (!deq.empty()){ pair<ii, ii> top = deq.front(); deq.pop_front(); int d = top.fi.fi, t = top.fi.se, b = top.se.fi, p = top.se.se; if (b == pos[1]){ ans = d; break; } //if (mymap[b].count(p)) continue; //mymap[b][p] = d; if (p <= k && dis[b][p][t] != inf) continue; if (p <= k) dis[b][p][t] = d; if (t == 0 && b-p >= 0) deq.pb(mp(mp(d+1, t), mp(b-p, p))); if (t == 1 && b+p < n) deq.pb(mp(mp(d+1, t), mp(b+p, p))); if (vis[b]) continue; vis[b] = 1; for (int j = 0; j < vec[b].size(); j++){ deq.push_front(mp(mp(d, 0), mp(b, vec[b][j]))); deq.push_front(mp(mp(d, 1), mp(b, vec[b][j]))); } } printf("%d\n", ans); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:56:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < vec[b].size(); j++){
                         ~~^~~~~~~~~~~~~~~
skyscraper.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &pos[i], &po[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...