제출 #339612

#제출 시각아이디문제언어결과실행 시간메모리
339612eyangchJakarta Skyscrapers (APIO15_skyscraper)C++17
22 / 100
33 ms1228 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(){ ios::sync_with_stdio(false); cin.tie(NULL); 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()){ if(~dist[b[1]]) break; int x = q.front().x, doge = q.front().doge, d = q.front().d; bool r = q.front().r; q.pop_front(); 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; x += dv; d++; while(x >= 0 && x < N && ~dist[x]){ x += dv; d++; } if(x < 0 || x >= N) continue; q.push_back({x, doge, d, 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...