# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
699239 | 2023-02-16T08:41:12 Z | nguyentunglam | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 1 ms | 1036 KB |
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 3e4 + 10, M = 8e6 + 10; map<pair<int, int>, int> dd; vector<int> lst[N]; int d[M]; int cnt; bool mark[N]; int id(int x, int y) { if (!dd[{x, y}]) dd[{x, y}] = ++cnt; return dd[{x, y}]; } int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int n, m; cin >> n >> m; while (m--) { int b, p; cin >> b >> p; lst[b].push_back(p); } deque<pair<int, int> > dq; for(int &j : lst[0]) { int code = id(0, j); if (!d[code]) { d[code] = 1; dq.push_back({0, j}); } } mark[0] = 1; while (!dq.empty()) { auto [pos, jump] = dq.front(); dq.pop_front(); int cur = id(pos, jump); if (pos == 1) return cout << d[cur] - 1, 0; if (!mark[pos]) { for(auto &j : lst[pos]) { int code = id(pos, j); if (!d[code]) d[code] = d[cur], dq.push_front({pos, j}); } mark[pos] = 1; } if (pos + jump < n) { int code = id(pos + jump, jump); if (!d[code]) d[code] = d[cur] + 1, dq.push_back({pos + jump, jump}); } if (pos - jump >= 0) { int code = id(pos - jump, jump); if (!d[code]) d[code] = d[cur] + 1, dq.push_back({pos - jump, jump}); } } cout << -1; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 980 KB | Output is correct |
2 | Incorrect | 1 ms | 980 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 980 KB | Output is correct |
2 | Incorrect | 1 ms | 980 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1036 KB | Output is correct |
2 | Incorrect | 1 ms | 1036 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 980 KB | Output is correct |
2 | Incorrect | 1 ms | 1036 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 980 KB | Output is correct |
2 | Incorrect | 1 ms | 980 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |