# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
45930 | 2018-04-16T13:50:20 Z | TheDarkning | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 1000 ms | 13636 KB |
#include <bits/stdc++.h> #define fr first #define sc second #define OK puts("OK"); #define pb push_back #define mk make_pair #define int long long using namespace std; typedef long long ll; const int inf = (int)1e15 + 7; const int N = (int)2e5 + 7; int n,m; int b[N],p[N]; int d[N]; vector <int> vec[N]; vector <pair<int,int> > g[N]; priority_queue<pair<int,int> > q; bool check (int l,int r,int x) { if (abs(r - l) % x == 0) return true; return false; } int f (int l,int r,int x) { return (abs(r - l) / x); } main () { scanf ("%lld%lld", &n,&m); for (int i = 1; i <= m; i ++) { scanf ("%lld%lld", &b[i],&p[i]); b[i] ++; vec[b[i]].pb(p[i]); } for (int i = 1; i <= n; i ++) { sort (vec[i].begin(),vec[i].end()); vec[i].erase(unique(vec[i].begin(),vec[i].end()),vec[i].end()); } for (int i = 1; i <= n; i ++) d[i] = inf; d[b[1]] = 0; q.push({0,b[1]}); while (!q.empty()) { int v = q.top().sc,cur = -q.top().fr; q.pop(); if (cur > d[v]) continue; if (b[2] == v) { printf("%lld\n", d[v]); return 0; } for (auto to : vec[v]) { for (int i = 1; to * i + v <= n; i ++) { if (d[v] + i < d[to * i + v]) { d[to * i + v] = d[v] + i; q.push({-d[to * i + v],to * i + v}); } } for (int i = 1; to * i <= v; i ++) { if (d[v] + i < d[v - to * i]) { d[v - to * i] = d[v] + i; q.push({-d[v - to * i],v - to * i}); } } } } if (d[b[2]] == inf) puts("-1"); else printf("%lld\n", d[b[2]]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9720 KB | Output is correct |
2 | Correct | 10 ms | 9720 KB | Output is correct |
3 | Correct | 9 ms | 9772 KB | Output is correct |
4 | Correct | 9 ms | 9816 KB | Output is correct |
5 | Correct | 9 ms | 9976 KB | Output is correct |
6 | Correct | 9 ms | 9976 KB | Output is correct |
7 | Correct | 9 ms | 9976 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 9976 KB | Output is correct |
2 | Correct | 9 ms | 10012 KB | Output is correct |
3 | Correct | 9 ms | 10084 KB | Output is correct |
4 | Correct | 9 ms | 10084 KB | Output is correct |
5 | Correct | 9 ms | 10084 KB | Output is correct |
6 | Correct | 9 ms | 10084 KB | Output is correct |
7 | Correct | 10 ms | 10096 KB | Output is correct |
8 | Correct | 9 ms | 10096 KB | Output is correct |
9 | Correct | 10 ms | 10096 KB | Output is correct |
10 | Correct | 9 ms | 10096 KB | Output is correct |
11 | Correct | 10 ms | 10096 KB | Output is correct |
12 | Correct | 10 ms | 10096 KB | Output is correct |
13 | Correct | 10 ms | 10096 KB | Output is correct |
14 | Correct | 12 ms | 10108 KB | Output is correct |
15 | Correct | 10 ms | 10108 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 10108 KB | Output is correct |
2 | Correct | 10 ms | 10108 KB | Output is correct |
3 | Correct | 10 ms | 10108 KB | Output is correct |
4 | Correct | 10 ms | 10108 KB | Output is correct |
5 | Correct | 10 ms | 10108 KB | Output is correct |
6 | Correct | 12 ms | 10108 KB | Output is correct |
7 | Correct | 12 ms | 10108 KB | Output is correct |
8 | Correct | 10 ms | 10108 KB | Output is correct |
9 | Correct | 10 ms | 10108 KB | Output is correct |
10 | Correct | 9 ms | 10108 KB | Output is correct |
11 | Correct | 10 ms | 10108 KB | Output is correct |
12 | Correct | 10 ms | 10108 KB | Output is correct |
13 | Correct | 12 ms | 10108 KB | Output is correct |
14 | Correct | 10 ms | 10108 KB | Output is correct |
15 | Correct | 10 ms | 10108 KB | Output is correct |
16 | Correct | 12 ms | 10108 KB | Output is correct |
17 | Correct | 11 ms | 10108 KB | Output is correct |
18 | Correct | 10 ms | 10108 KB | Output is correct |
19 | Correct | 10 ms | 10108 KB | Output is correct |
20 | Correct | 17 ms | 10108 KB | Output is correct |
21 | Correct | 10 ms | 10108 KB | Output is correct |
22 | Correct | 12 ms | 10108 KB | Output is correct |
23 | Correct | 11 ms | 10112 KB | Output is correct |
24 | Correct | 12 ms | 10112 KB | Output is correct |
25 | Correct | 10 ms | 10152 KB | Output is correct |
26 | Correct | 13 ms | 10152 KB | Output is correct |
27 | Correct | 10 ms | 10152 KB | Output is correct |
28 | Correct | 14 ms | 10152 KB | Output is correct |
29 | Correct | 11 ms | 10444 KB | Output is correct |
30 | Correct | 11 ms | 10444 KB | Output is correct |
31 | Correct | 10 ms | 10444 KB | Output is correct |
32 | Correct | 10 ms | 10444 KB | Output is correct |
33 | Correct | 13 ms | 10444 KB | Output is correct |
34 | Correct | 13 ms | 10500 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 10500 KB | Output is correct |
2 | Correct | 10 ms | 10500 KB | Output is correct |
3 | Correct | 10 ms | 10500 KB | Output is correct |
4 | Correct | 9 ms | 10500 KB | Output is correct |
5 | Correct | 10 ms | 10500 KB | Output is correct |
6 | Correct | 9 ms | 10500 KB | Output is correct |
7 | Correct | 9 ms | 10500 KB | Output is correct |
8 | Correct | 9 ms | 10500 KB | Output is correct |
9 | Correct | 10 ms | 10500 KB | Output is correct |
10 | Correct | 9 ms | 10500 KB | Output is correct |
11 | Correct | 9 ms | 10500 KB | Output is correct |
12 | Correct | 10 ms | 10500 KB | Output is correct |
13 | Correct | 10 ms | 10500 KB | Output is correct |
14 | Correct | 10 ms | 10500 KB | Output is correct |
15 | Correct | 10 ms | 10500 KB | Output is correct |
16 | Correct | 10 ms | 10500 KB | Output is correct |
17 | Correct | 11 ms | 10500 KB | Output is correct |
18 | Correct | 10 ms | 10500 KB | Output is correct |
19 | Correct | 11 ms | 10500 KB | Output is correct |
20 | Correct | 15 ms | 10500 KB | Output is correct |
21 | Correct | 10 ms | 10500 KB | Output is correct |
22 | Correct | 9 ms | 10500 KB | Output is correct |
23 | Correct | 11 ms | 10500 KB | Output is correct |
24 | Correct | 11 ms | 10500 KB | Output is correct |
25 | Correct | 14 ms | 10500 KB | Output is correct |
26 | Correct | 14 ms | 10500 KB | Output is correct |
27 | Correct | 13 ms | 10500 KB | Output is correct |
28 | Correct | 11 ms | 10500 KB | Output is correct |
29 | Correct | 13 ms | 10500 KB | Output is correct |
30 | Correct | 13 ms | 10500 KB | Output is correct |
31 | Correct | 14 ms | 10500 KB | Output is correct |
32 | Correct | 14 ms | 10500 KB | Output is correct |
33 | Correct | 16 ms | 10500 KB | Output is correct |
34 | Correct | 16 ms | 10500 KB | Output is correct |
35 | Correct | 24 ms | 10876 KB | Output is correct |
36 | Correct | 12 ms | 10876 KB | Output is correct |
37 | Correct | 24 ms | 10876 KB | Output is correct |
38 | Correct | 21 ms | 11132 KB | Output is correct |
39 | Correct | 29 ms | 11132 KB | Output is correct |
40 | Correct | 25 ms | 11132 KB | Output is correct |
41 | Correct | 30 ms | 11196 KB | Output is correct |
42 | Correct | 17 ms | 11196 KB | Output is correct |
43 | Correct | 16 ms | 11196 KB | Output is correct |
44 | Correct | 25 ms | 11196 KB | Output is correct |
45 | Correct | 21 ms | 11260 KB | Output is correct |
46 | Correct | 28 ms | 11260 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 11260 KB | Output is correct |
2 | Correct | 11 ms | 11260 KB | Output is correct |
3 | Correct | 13 ms | 11260 KB | Output is correct |
4 | Correct | 10 ms | 11260 KB | Output is correct |
5 | Correct | 12 ms | 11260 KB | Output is correct |
6 | Correct | 10 ms | 11260 KB | Output is correct |
7 | Correct | 12 ms | 11260 KB | Output is correct |
8 | Correct | 13 ms | 11260 KB | Output is correct |
9 | Correct | 11 ms | 11260 KB | Output is correct |
10 | Correct | 12 ms | 11260 KB | Output is correct |
11 | Correct | 11 ms | 11260 KB | Output is correct |
12 | Correct | 13 ms | 11260 KB | Output is correct |
13 | Correct | 10 ms | 11260 KB | Output is correct |
14 | Correct | 13 ms | 11260 KB | Output is correct |
15 | Correct | 11 ms | 11260 KB | Output is correct |
16 | Correct | 12 ms | 11260 KB | Output is correct |
17 | Correct | 14 ms | 11260 KB | Output is correct |
18 | Correct | 10 ms | 11260 KB | Output is correct |
19 | Correct | 12 ms | 11260 KB | Output is correct |
20 | Correct | 16 ms | 11260 KB | Output is correct |
21 | Correct | 13 ms | 11260 KB | Output is correct |
22 | Correct | 12 ms | 11260 KB | Output is correct |
23 | Correct | 11 ms | 11260 KB | Output is correct |
24 | Correct | 11 ms | 11260 KB | Output is correct |
25 | Correct | 10 ms | 11260 KB | Output is correct |
26 | Correct | 12 ms | 11260 KB | Output is correct |
27 | Correct | 14 ms | 11260 KB | Output is correct |
28 | Correct | 13 ms | 11260 KB | Output is correct |
29 | Correct | 14 ms | 11260 KB | Output is correct |
30 | Correct | 10 ms | 11260 KB | Output is correct |
31 | Correct | 11 ms | 11260 KB | Output is correct |
32 | Correct | 11 ms | 11260 KB | Output is correct |
33 | Correct | 15 ms | 11260 KB | Output is correct |
34 | Correct | 15 ms | 11260 KB | Output is correct |
35 | Correct | 26 ms | 11260 KB | Output is correct |
36 | Correct | 12 ms | 11260 KB | Output is correct |
37 | Correct | 23 ms | 11260 KB | Output is correct |
38 | Correct | 30 ms | 11260 KB | Output is correct |
39 | Correct | 26 ms | 11260 KB | Output is correct |
40 | Correct | 28 ms | 11260 KB | Output is correct |
41 | Correct | 21 ms | 11260 KB | Output is correct |
42 | Correct | 20 ms | 11260 KB | Output is correct |
43 | Correct | 19 ms | 11260 KB | Output is correct |
44 | Correct | 27 ms | 11260 KB | Output is correct |
45 | Correct | 21 ms | 11260 KB | Output is correct |
46 | Correct | 19 ms | 11260 KB | Output is correct |
47 | Correct | 23 ms | 12024 KB | Output is correct |
48 | Correct | 19 ms | 12024 KB | Output is correct |
49 | Correct | 20 ms | 12024 KB | Output is correct |
50 | Correct | 18 ms | 12024 KB | Output is correct |
51 | Correct | 39 ms | 13636 KB | Output is correct |
52 | Correct | 36 ms | 13636 KB | Output is correct |
53 | Correct | 26 ms | 13636 KB | Output is correct |
54 | Correct | 16 ms | 13636 KB | Output is correct |
55 | Correct | 15 ms | 13636 KB | Output is correct |
56 | Execution timed out | 1036 ms | 13636 KB | Time limit exceeded |
57 | Halted | 0 ms | 0 KB | - |