제출 #260895

#제출 시각아이디문제언어결과실행 시간메모리
260895atoizJakarta Skyscrapers (APIO15_skyscraper)C++14
22 / 100
10 ms5424 KiB
#include <iostream> #include <vector> #include <algorithm> #include <unordered_map> #include <cassert> using namespace std; const int MAXN = (1 << 15), QUEUE_SIZE = 40000000; vector<int> powers[MAXN]; unordered_map<int, int> dist; int N, M, S, T; int qu[MAXN], top; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N >> M; for (int i = 0; i < M; ++i) { int b, p; cin >> b >> p; if (i == 0) S = b; else if (i == 1) T = b; powers[b].push_back(p); } qu[0] = S * MAXN, top = 0; for (int qi = 0; qi <= top; ++qi) { int u = qu[qi] / MAXN, d = qu[qi] & (MAXN - 1), c = dist[qu[qi]]; if (u == T) return cout << c << endl, 0; powers[u].push_back(d); for (int d0 : powers[u]) { if (dist.find(u * MAXN + d0) == dist.end()) dist[u * MAXN + d0] = c; if (u - d0 >= 0 && dist.find((u - d0) * MAXN + d0) == dist.end()) { dist[qu[++top] = (u - d0) * MAXN + d0] = c + 1; } if (u + d0 < N && dist.find((u + d0) * MAXN + d0) == dist.end()) { dist[qu[++top] = (u + d0) * MAXN + d0] = c + 1; } } powers[u].clear(); } cout << -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...