Submission #339605

#TimeUsernameProblemLanguageResultExecution timeMemory
339605eyangchJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1088 ms2924 KiB
#include <bits/stdc++.h> using namespace std; struct loc{int x; int doge; int d; bool r;}; int N, M; int b[30000], p[30000]; vector<int> graph[30000]; int dist[30000]; signed main(){ cin >> N >> M; for(int i = 0; i < M; i++){ cin >> b[i] >> p[i]; graph[b[i]].push_back(i); } fill(dist, dist+N, -1); deque<loc> q; q.push_back({b[0], 0, 0, true}); q.push_back({b[0], 0, 0, false}); while(!q.empty()){ int x = q.front().x, doge = q.front().doge, d = q.front().d; bool r = q.front().r; q.pop_front(); if(x < 0 || x >= N) continue; if(!(~dist[x])){ dist[x] = d; for(int i : graph[x]){ if(i != doge){ q.push_front({x, i, d, true}); q.push_front({x, i, d, false}); } } } int dv = p[doge]; if(!r) dv = -dv; q.push_back({x+dv, doge, d+1, r}); } cout << dist[b[1]] << endl; }
#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...