# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
45848 | 2018-04-16T09:21:23 Z | antimirage | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 2 ms | 620 KB |
#include <bits/stdc++.h> #define fr first #define sc second #define mk make_pair #define pb push_back #define OK puts("OK"); #define sz(s) (int)s.size() #define all(s) s.begin(), s.end() using namespace std; const int N = 2005; int n, m, u[N][N], pos[N], pw[N], ans = 1e9 + 7; vector <int> vec[N]; queue <pair <int, int> > q; main() { cin >> n >> m; for (int i = 0; i < m; i++) { scanf("%d%d", &pos[i], &pw[i]); vec[pos[i]].pb(pw[i]); } for (auto to : vec[ pos[0] ]) { q.push( mk(pos[0], to) ); u[ pos[0] ][to] = 1; } vec[ pos[0] ].clear(); while (!q.empty() ) { int v = q.front().fr, cur_pow = q.front().sc; q.pop(); for (auto it : vec[v]) { if (!u[v][it]) { u[v][it] = u[v][cur_pow]; q.push( mk(v, it) ); } } vec[v].clear(); if ( v - cur_pow >= 0 && !u[v - cur_pow][cur_pow] ) { u[v - cur_pow][cur_pow] = u[v][cur_pow] + 1; q.push( mk(v - cur_pow, cur_pow) ); } if ( v + cur_pow < n && !u[v + cur_pow][cur_pow] ) { u[v + cur_pow][cur_pow] = u[v][cur_pow] + 1; q.push( mk(v + cur_pow, cur_pow) ); } } for (int i = 0; i < m; i++) { if (u[ pos[1] ][i]) ans = min(ans, u[ pos[1] ][i] - 1); } if (ans == 1e9 + 7) ans = -1; cout << ans << endl; } /** 5 3 0 2 1 1 4 1 **/
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 484 KB | Output is correct |
3 | Incorrect | 2 ms | 568 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 568 KB | Output is correct |
2 | Correct | 2 ms | 568 KB | Output is correct |
3 | Incorrect | 2 ms | 568 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 592 KB | Output is correct |
2 | Correct | 2 ms | 592 KB | Output is correct |
3 | Incorrect | 2 ms | 592 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 596 KB | Output is correct |
2 | Correct | 2 ms | 620 KB | Output is correct |
3 | Incorrect | 2 ms | 620 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 620 KB | Output is correct |
2 | Correct | 2 ms | 620 KB | Output is correct |
3 | Incorrect | 2 ms | 620 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |