Submission #229701

#TimeUsernameProblemLanguageResultExecution timeMemory
229701NightlightPalembang Bridges (APIO15_bridge)C++14
0 / 100
13 ms15232 KiB
#include <queue> #include <cstdio> #include <cstring> #include <set> #define pii pair<int, int> #define piii tuple<int, int, int> #define mt make_tuple #define push_back emplace_back using namespace std; int N, M; int pos, mov, sta, fin; vector<pii> adj[30005]; set<int> here[300005]; int dist[30005]; void BFS() { memset(dist, 0x3f3f3f3f, sizeof(dist)); priority_queue<pii, vector<pii>, greater<pii>> pq; pq.push(make_pair(0, sta)); dist[sta] = 0; while(!pq.empty()) { int u = pq.top().second; int now = pq.top().first; pq.pop(); if(dist[u] < now) continue; for(pii v : adj[u]) { if(dist[u] + v.second < dist[v.first]) { dist[v.first] = dist[u] + v.second; pq.push(make_pair(dist[v.first], v.first)); } } } if(dist[fin] == 0x3f3f3f3f) puts("-1"); else printf("%d\n", dist[fin]); } int main() { scanf("%d %d", &N, &M); scanf("%d %d", &pos, &mov); here[pos].insert(mov); sta = pos; scanf("%d %d", &pos, &mov); here[pos].insert(mov); fin = pos; for(int i = 2; i < M; i++) { scanf("%d %d", &pos, &mov); here[pos].insert(mov); } for(int i = 0; i <= N; i++) { if(i == fin) continue; for(int now : here[i]) { for(int nxt = i - now, p = 1; nxt >= 0; nxt -= now, p++) { adj[i].push_back(nxt, p); if(here[nxt].count(p)) break; } for(int nxt = i + now, p = 1; nxt <= N; nxt += now, p++) { adj[i].push_back(nxt, p); if(here[nxt].count(p)) break; } } } BFS(); }

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &N, &M);
   ~~~~~^~~~~~~~~~~~~~~~~
bridge.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &pos, &mov);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
bridge.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &pos, &mov);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
bridge.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &pos, &mov);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...