# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
123917 | AyaBenSaad | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 270 ms | 238340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 3; //number of skyscrapers
const int M = 3e4 + 4; //number of doges;
const int inf = 2e9;
int n, m, b[M], p[M], ok;
vector <int> dgin[N];
int dp[M][N];
int solve (int doge, int sk) {
if (doge == 1) {ok = 1; return 0;}
if (sk < 0 || sk >= n) return inf;
int &ret = dp[doge][sk];
if (ret != -1) return ret;
ret = solve(doge, sk+p[doge]) + 1;
ret = min(ret, solve(doge, sk-p[doge]) + 1);
for (int i : dgin[sk]) {
if (i != doge) ret = min (ret, solve(i, sk));
}
return ret;
}
int main () {
scanf ("%d %d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d %d", &b[i], &p[i]);
dgin[b[i]].push_back (i);
}
memset (dp, -1, sizeof dp);
int x = solve(0, b[0]);
if(ok) printf("%d\n", x);
else puts("-1");
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |