# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41507 | 2018-02-17T15:24:27 Z | fest | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1000 ms | 7276 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("1.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 = 200500, 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}; int dp[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++) sort(All(have[i])); for (int i = 0; i < n; i++) dp[i] = inf; dp[start] = 0; set<pair<int, int> > s; s.insert({0, start}); while (!s.empty()) { int v = s.begin() -> S; s.erase(s.begin()); for (auto p : have[v]) { for (int mul = 1; v + mul * p < n; mul++) { int u = v + mul * p; if (dp[u] > dp[v] + mul) { s.erase({dp[u], u}); dp[u] = dp[v] + mul; s.insert({dp[u], u}); } auto now = lower_bound(All(have[u]), p); if (now != have[u].end() && *now == p) break; } for (int mul = 1; v - mul * p >= 0; mul++) { int u = v - mul * p; if (dp[u] > dp[v] + mul) { s.erase({dp[u], u}); dp[u] = dp[v] + mul; s.insert({dp[u], u}); } auto now = lower_bound(All(have[u]), p); if (now != have[u].end() && *now == p) break; } } } if (dp[finish] == inf) dp[finish] = -1; cout << dp[finish]; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 4984 KB | Output is correct |
2 | Correct | 5 ms | 5216 KB | Output is correct |
3 | Correct | 5 ms | 5216 KB | Output is correct |
4 | Correct | 6 ms | 5216 KB | Output is correct |
5 | Correct | 5 ms | 5216 KB | Output is correct |
6 | Correct | 5 ms | 5216 KB | Output is correct |
7 | Correct | 5 ms | 5216 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 5312 KB | Output is correct |
2 | Correct | 5 ms | 5352 KB | Output is correct |
3 | Correct | 5 ms | 5352 KB | Output is correct |
4 | Correct | 5 ms | 5352 KB | Output is correct |
5 | Correct | 5 ms | 5352 KB | Output is correct |
6 | Correct | 5 ms | 5352 KB | Output is correct |
7 | Correct | 5 ms | 5356 KB | Output is correct |
8 | Correct | 5 ms | 5356 KB | Output is correct |
9 | Correct | 5 ms | 5356 KB | Output is correct |
10 | Correct | 5 ms | 5356 KB | Output is correct |
11 | Correct | 6 ms | 5356 KB | Output is correct |
12 | Correct | 6 ms | 5356 KB | Output is correct |
13 | Correct | 6 ms | 5356 KB | Output is correct |
14 | Correct | 6 ms | 5356 KB | Output is correct |
15 | Correct | 6 ms | 5356 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 5356 KB | Output is correct |
2 | Correct | 5 ms | 5356 KB | Output is correct |
3 | Correct | 5 ms | 5356 KB | Output is correct |
4 | Correct | 6 ms | 5356 KB | Output is correct |
5 | Correct | 5 ms | 5356 KB | Output is correct |
6 | Correct | 5 ms | 5356 KB | Output is correct |
7 | Correct | 6 ms | 5356 KB | Output is correct |
8 | Correct | 5 ms | 5356 KB | Output is correct |
9 | Correct | 5 ms | 5356 KB | Output is correct |
10 | Correct | 6 ms | 5356 KB | Output is correct |
11 | Correct | 6 ms | 5356 KB | Output is correct |
12 | Correct | 7 ms | 5356 KB | Output is correct |
13 | Correct | 6 ms | 5356 KB | Output is correct |
14 | Correct | 6 ms | 5356 KB | Output is correct |
15 | Correct | 6 ms | 5356 KB | Output is correct |
16 | Correct | 6 ms | 5356 KB | Output is correct |
17 | Correct | 6 ms | 5356 KB | Output is correct |
18 | Correct | 7 ms | 5356 KB | Output is correct |
19 | Correct | 5 ms | 5356 KB | Output is correct |
20 | Correct | 5 ms | 5356 KB | Output is correct |
21 | Correct | 6 ms | 5356 KB | Output is correct |
22 | Correct | 5 ms | 5356 KB | Output is correct |
23 | Correct | 6 ms | 5356 KB | Output is correct |
24 | Correct | 9 ms | 5360 KB | Output is correct |
25 | Correct | 7 ms | 5360 KB | Output is correct |
26 | Correct | 15 ms | 5360 KB | Output is correct |
27 | Correct | 15 ms | 5456 KB | Output is correct |
28 | Correct | 6 ms | 5456 KB | Output is correct |
29 | Correct | 12 ms | 5456 KB | Output is correct |
30 | Correct | 6 ms | 5456 KB | Output is correct |
31 | Correct | 7 ms | 5456 KB | Output is correct |
32 | Correct | 7 ms | 5484 KB | Output is correct |
33 | Correct | 11 ms | 5484 KB | Output is correct |
34 | Correct | 11 ms | 5484 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 5484 KB | Output is correct |
2 | Correct | 5 ms | 5484 KB | Output is correct |
3 | Correct | 6 ms | 5484 KB | Output is correct |
4 | Correct | 5 ms | 5484 KB | Output is correct |
5 | Correct | 5 ms | 5484 KB | Output is correct |
6 | Correct | 5 ms | 5484 KB | Output is correct |
7 | Correct | 5 ms | 5484 KB | Output is correct |
8 | Correct | 5 ms | 5484 KB | Output is correct |
9 | Correct | 5 ms | 5484 KB | Output is correct |
10 | Correct | 5 ms | 5484 KB | Output is correct |
11 | Correct | 7 ms | 5484 KB | Output is correct |
12 | Correct | 6 ms | 5484 KB | Output is correct |
13 | Correct | 5 ms | 5484 KB | Output is correct |
14 | Correct | 5 ms | 5484 KB | Output is correct |
15 | Correct | 6 ms | 5484 KB | Output is correct |
16 | Correct | 5 ms | 5484 KB | Output is correct |
17 | Correct | 6 ms | 5484 KB | Output is correct |
18 | Correct | 5 ms | 5484 KB | Output is correct |
19 | Correct | 5 ms | 5484 KB | Output is correct |
20 | Correct | 5 ms | 5484 KB | Output is correct |
21 | Correct | 6 ms | 5484 KB | Output is correct |
22 | Correct | 6 ms | 5484 KB | Output is correct |
23 | Correct | 6 ms | 5488 KB | Output is correct |
24 | Correct | 7 ms | 5488 KB | Output is correct |
25 | Correct | 7 ms | 5488 KB | Output is correct |
26 | Correct | 15 ms | 5488 KB | Output is correct |
27 | Correct | 14 ms | 5488 KB | Output is correct |
28 | Correct | 6 ms | 5488 KB | Output is correct |
29 | Correct | 9 ms | 5488 KB | Output is correct |
30 | Correct | 7 ms | 5488 KB | Output is correct |
31 | Correct | 7 ms | 5488 KB | Output is correct |
32 | Correct | 7 ms | 5488 KB | Output is correct |
33 | Correct | 12 ms | 5488 KB | Output is correct |
34 | Correct | 12 ms | 5488 KB | Output is correct |
35 | Correct | 15 ms | 5488 KB | Output is correct |
36 | Correct | 10 ms | 5488 KB | Output is correct |
37 | Correct | 16 ms | 5556 KB | Output is correct |
38 | Correct | 19 ms | 5612 KB | Output is correct |
39 | Correct | 27 ms | 5612 KB | Output is correct |
40 | Correct | 19 ms | 5612 KB | Output is correct |
41 | Correct | 20 ms | 5612 KB | Output is correct |
42 | Correct | 166 ms | 5612 KB | Output is correct |
43 | Correct | 147 ms | 5612 KB | Output is correct |
44 | Correct | 13 ms | 5612 KB | Output is correct |
45 | Correct | 19 ms | 5612 KB | Output is correct |
46 | Correct | 19 ms | 5612 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 5612 KB | Output is correct |
2 | Correct | 5 ms | 5612 KB | Output is correct |
3 | Correct | 5 ms | 5612 KB | Output is correct |
4 | Correct | 5 ms | 5612 KB | Output is correct |
5 | Correct | 5 ms | 5612 KB | Output is correct |
6 | Correct | 6 ms | 5612 KB | Output is correct |
7 | Correct | 6 ms | 5612 KB | Output is correct |
8 | Correct | 5 ms | 5612 KB | Output is correct |
9 | Correct | 5 ms | 5612 KB | Output is correct |
10 | Correct | 6 ms | 5612 KB | Output is correct |
11 | Correct | 6 ms | 5612 KB | Output is correct |
12 | Correct | 7 ms | 5612 KB | Output is correct |
13 | Correct | 5 ms | 5612 KB | Output is correct |
14 | Correct | 7 ms | 5612 KB | Output is correct |
15 | Correct | 5 ms | 5612 KB | Output is correct |
16 | Correct | 5 ms | 5612 KB | Output is correct |
17 | Correct | 6 ms | 5612 KB | Output is correct |
18 | Correct | 5 ms | 5612 KB | Output is correct |
19 | Correct | 5 ms | 5612 KB | Output is correct |
20 | Correct | 5 ms | 5612 KB | Output is correct |
21 | Correct | 5 ms | 5612 KB | Output is correct |
22 | Correct | 5 ms | 5612 KB | Output is correct |
23 | Correct | 6 ms | 5612 KB | Output is correct |
24 | Correct | 8 ms | 5612 KB | Output is correct |
25 | Correct | 8 ms | 5612 KB | Output is correct |
26 | Correct | 15 ms | 5612 KB | Output is correct |
27 | Correct | 14 ms | 5612 KB | Output is correct |
28 | Correct | 6 ms | 5612 KB | Output is correct |
29 | Correct | 9 ms | 5612 KB | Output is correct |
30 | Correct | 7 ms | 5612 KB | Output is correct |
31 | Correct | 8 ms | 5612 KB | Output is correct |
32 | Correct | 7 ms | 5612 KB | Output is correct |
33 | Correct | 12 ms | 5612 KB | Output is correct |
34 | Correct | 14 ms | 5612 KB | Output is correct |
35 | Correct | 15 ms | 5612 KB | Output is correct |
36 | Correct | 7 ms | 5612 KB | Output is correct |
37 | Correct | 16 ms | 5612 KB | Output is correct |
38 | Correct | 21 ms | 5612 KB | Output is correct |
39 | Correct | 20 ms | 5612 KB | Output is correct |
40 | Correct | 20 ms | 5612 KB | Output is correct |
41 | Correct | 21 ms | 5612 KB | Output is correct |
42 | Correct | 170 ms | 5612 KB | Output is correct |
43 | Correct | 160 ms | 5612 KB | Output is correct |
44 | Correct | 12 ms | 5612 KB | Output is correct |
45 | Correct | 22 ms | 5612 KB | Output is correct |
46 | Correct | 23 ms | 5612 KB | Output is correct |
47 | Correct | 49 ms | 6124 KB | Output is correct |
48 | Correct | 13 ms | 6124 KB | Output is correct |
49 | Correct | 13 ms | 6124 KB | Output is correct |
50 | Correct | 11 ms | 6124 KB | Output is correct |
51 | Correct | 81 ms | 7276 KB | Output is correct |
52 | Correct | 90 ms | 7276 KB | Output is correct |
53 | Correct | 34 ms | 7276 KB | Output is correct |
54 | Correct | 9 ms | 7276 KB | Output is correct |
55 | Correct | 11 ms | 7276 KB | Output is correct |
56 | Correct | 28 ms | 7276 KB | Output is correct |
57 | Correct | 71 ms | 7276 KB | Output is correct |
58 | Execution timed out | 1072 ms | 7276 KB | Time limit exceeded |
59 | Halted | 0 ms | 0 KB | - |