# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
41419 | 2018-02-17T07:57:45 Z | fest | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 2 ms | 732 KB |
// fest #include <bits/stdc++.h> #define pb push_back #define F first #define S second #define y1 dasdasfasfas #define x1 wqdadfasfasfas #define All(c) c.begin(), c.end() #define SZ(A) (int((A).size())) #define umap unordered_map #define FILENAME "" #define __ fflush(stdout) typedef long long ll; typedef long double ld; using namespace std; void FREOPEN() { #ifdef COMP freopen(".in", "r", stdin); freopen("2.out", "w", stdout); #else freopen(FILENAME".in", "r", stdin); freopen(FILENAME".out", "w", stdout); #endif } inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; } const int N = 2001, inf = 1e9 * 2, MOD = (int)1e9 + 7; char CH[N]; const ll INF = 1e18; const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1}; const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1}; bool was[N][N]; int dp[N][N]; vector<int> have[N]; int main() { int n, m; scanf("%d %d", &n, &m); int start = 0, finish = 0; for (int i = 0; i < m; i++) { int b, p; scanf("%d %d", &b, &p); have[b].pb(p); if (i == 0) start = b; if (i == 1) finish = b; } for (int i = 0; i < n; i++) for (int j = 0; j < N; j++) dp[i][j] = inf; vector<pair<int, int> > vers; for (auto i : have[start]) dp[start][i] = 0, was[start][i] = 1, vers.pb({start, i}); int l = 0; while (l < SZ(vers)) { int v = vers[l].F; int p = vers[l].S; l++; if (v + p < n) { if (!was[v + p][p]) { was[v + p][p] = 1; dp[v + p][p] = dp[v][p] + 1; vers.pb({v + p, p}); if (!have[v + p].empty()) { if (!was[v + p][have[v + p][0]]) { for (auto i : have[v + p]) { was[v + p][i] = 1; dp[v + p][i] = dp[v][p] + 1; vers.pb({v + p, i}); } } } } } if (v - p >= 0) { if (!was[v - p][p]) { was[v - p][p] = 1; dp[v - p][p] = dp[v][p] + 1; vers.pb({v - p, p}); if (!have[v - p].empty()) { if (!was[v - p][have[v - p][0]]) { for (auto i : have[v - p]) { was[v - p][i] = 1; dp[v - p][i] = dp[v][p] + 1; vers.pb({v - p, i}); } } } } } } int out = inf; for (int i = 0; i < N; i++) out = min(out, dp[finish][i]); cout << out; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 532 KB | Output is correct |
4 | Incorrect | 2 ms | 532 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 732 KB | Output is correct |
2 | Correct | 2 ms | 732 KB | Output is correct |
3 | Correct | 2 ms | 732 KB | Output is correct |
4 | Incorrect | 2 ms | 732 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 732 KB | Output is correct |
2 | Correct | 2 ms | 732 KB | Output is correct |
3 | Correct | 2 ms | 732 KB | Output is correct |
4 | Incorrect | 2 ms | 732 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 732 KB | Output is correct |
2 | Correct | 2 ms | 732 KB | Output is correct |
3 | Correct | 2 ms | 732 KB | Output is correct |
4 | Incorrect | 2 ms | 732 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 732 KB | Output is correct |
2 | Correct | 2 ms | 732 KB | Output is correct |
3 | Correct | 2 ms | 732 KB | Output is correct |
4 | Incorrect | 2 ms | 732 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |