Submission #907158

#TimeUsernameProblemLanguageResultExecution timeMemory
907158yellowtoadJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1093 ms109604 KiB
#include <iostream> #include <map> #include <vector> #include <queue> #define f first #define s second using namespace std; int n, m, cnt, st, ed, dist[10000010], vis[10000010]; map<pair<int,int>,int> mp; vector<vector<pair<int,int>>> edge; deque<int> q; int main() { cin >> n >> m; cnt = n-1; for (int i = 0; i < n; i++) edge.push_back({}); for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; if (i == 1) st = u; if (i == 2) ed = u; if (!mp[{u,v}]) { for (int j = u%v; j < n; j += v) { mp[{j,v}] = ++cnt; edge.push_back({{j,0}}); if (j != u%v) { edge[cnt].push_back({cnt-1,1}); edge[cnt-1].push_back({cnt,1}); } } } edge[u].push_back({mp[{u,v}],0}); } for (int i = 0; i <= cnt; i++) dist[i] = 1e9; q.push_back(st); dist[st] = 0; while (q.size()) { int u = q.front(); q.pop_front(); if (vis[u]) continue; vis[u] = 1; for (int i = 0; i < edge[u].size(); i++) { if (dist[edge[u][i].f] > dist[u]+edge[u][i].s) { dist[edge[u][i].f] = dist[u]+edge[u][i].s; if (edge[u][i].s) q.push_back(edge[u][i].f); else q.push_front(edge[u][i].f); } } } if (dist[ed] == 1e9) cout << -1 << endl; else cout << dist[ed] << endl; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:43:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   for (int i = 0; i < edge[u].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...