# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
115654 | 2019-06-08T12:35:13 Z | imyujin | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 696 ms | 6120 KB |
#include<stdio.h> #include<vector> #include<queue> #include<algorithm> using namespace std; #define MAXN 30005 #define MAXM 30005 #define LINF 8100000000ll #define fi first #define se second typedef pair<int, int> pi; long long dp[MAXN]; int B[MAXM], P[MAXM]; vector<int> d[MAXN]; priority_queue<pi, vector<pi>, greater<pi> > pq; int main(){ int N, M; scanf("%d%d", &N, &M); for(int i=0; i<M; i++) scanf("%d%d", B+i, P+i); for(int i=0; i<M; i++) d[B[i]].push_back(P[i]); for(int i=0; i<N; i++){ sort(d[i].begin(), d[i].end()); unique(d[i].begin(), d[i].end()); } pq.push(make_pair(0, B[0])); for(int i=0; i<N; i++) dp[i]=LINF; dp[B[0]]=0; while(!pq.empty()){ pi t=pq.top(); pq.pop(); if(t.se==B[1]){ printf("%lld", dp[B[1]]); return 0; } for(int j=0; j<d[t.se].size(); j++){ int l=t.se+d[t.se][j]; for(int k=1; l<N; k++, l+=d[t.se][j]){ if(t.fi+k<dp[l]){ dp[l]=t.fi+k; pq.push(make_pair(t.fi+k, l)); } //if(lower_bound(d[l].begin(), d[l].end(), d[t.se][j])!=d[l].end()) break; } l=t.se-d[t.se][j]; for(int k=1; l>=0; k++, l-=d[t.se][j]){ if(t.fi+k<dp[l]){ dp[l]=t.fi+k; pq.push(make_pair(t.fi+k, l)); } //if(lower_bound(d[l].begin(), d[l].end(), d[t.se][j])!=d[l].end()) break; } } } printf("-1"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1024 KB | Output is correct |
2 | Correct | 2 ms | 1024 KB | Output is correct |
3 | Correct | 2 ms | 1024 KB | Output is correct |
4 | Correct | 2 ms | 1024 KB | Output is correct |
5 | Correct | 3 ms | 1024 KB | Output is correct |
6 | Correct | 3 ms | 1024 KB | Output is correct |
7 | Correct | 2 ms | 896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1024 KB | Output is correct |
2 | Correct | 3 ms | 1024 KB | Output is correct |
3 | Correct | 2 ms | 1024 KB | Output is correct |
4 | Correct | 2 ms | 1024 KB | Output is correct |
5 | Correct | 3 ms | 1024 KB | Output is correct |
6 | Correct | 3 ms | 1152 KB | Output is correct |
7 | Correct | 3 ms | 964 KB | Output is correct |
8 | Correct | 3 ms | 1024 KB | Output is correct |
9 | Correct | 2 ms | 1024 KB | Output is correct |
10 | Correct | 2 ms | 1024 KB | Output is correct |
11 | Correct | 3 ms | 1152 KB | Output is correct |
12 | Correct | 3 ms | 1024 KB | Output is correct |
13 | Correct | 3 ms | 1024 KB | Output is correct |
14 | Correct | 3 ms | 1152 KB | Output is correct |
15 | Correct | 3 ms | 1024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1024 KB | Output is correct |
2 | Correct | 3 ms | 1024 KB | Output is correct |
3 | Correct | 2 ms | 1024 KB | Output is correct |
4 | Correct | 2 ms | 1024 KB | Output is correct |
5 | Correct | 2 ms | 1024 KB | Output is correct |
6 | Correct | 2 ms | 1024 KB | Output is correct |
7 | Correct | 2 ms | 1024 KB | Output is correct |
8 | Correct | 2 ms | 1024 KB | Output is correct |
9 | Correct | 2 ms | 1024 KB | Output is correct |
10 | Correct | 2 ms | 1024 KB | Output is correct |
11 | Correct | 3 ms | 1024 KB | Output is correct |
12 | Correct | 2 ms | 1024 KB | Output is correct |
13 | Correct | 3 ms | 1024 KB | Output is correct |
14 | Correct | 3 ms | 1024 KB | Output is correct |
15 | Correct | 3 ms | 1152 KB | Output is correct |
16 | Correct | 2 ms | 1024 KB | Output is correct |
17 | Correct | 3 ms | 1152 KB | Output is correct |
18 | Correct | 2 ms | 1152 KB | Output is correct |
19 | Correct | 3 ms | 1152 KB | Output is correct |
20 | Correct | 7 ms | 1152 KB | Output is correct |
21 | Correct | 3 ms | 1024 KB | Output is correct |
22 | Correct | 3 ms | 1152 KB | Output is correct |
23 | Correct | 3 ms | 1024 KB | Output is correct |
24 | Correct | 3 ms | 1152 KB | Output is correct |
25 | Correct | 3 ms | 1152 KB | Output is correct |
26 | Correct | 3 ms | 1152 KB | Output is correct |
27 | Correct | 3 ms | 1280 KB | Output is correct |
28 | Correct | 4 ms | 1152 KB | Output is correct |
29 | Correct | 4 ms | 1280 KB | Output is correct |
30 | Correct | 4 ms | 1152 KB | Output is correct |
31 | Correct | 3 ms | 1152 KB | Output is correct |
32 | Correct | 4 ms | 1152 KB | Output is correct |
33 | Correct | 6 ms | 1408 KB | Output is correct |
34 | Correct | 5 ms | 1408 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1024 KB | Output is correct |
2 | Correct | 2 ms | 1024 KB | Output is correct |
3 | Correct | 3 ms | 1024 KB | Output is correct |
4 | Correct | 2 ms | 1024 KB | Output is correct |
5 | Correct | 2 ms | 1024 KB | Output is correct |
6 | Correct | 3 ms | 1024 KB | Output is correct |
7 | Correct | 2 ms | 1024 KB | Output is correct |
8 | Correct | 2 ms | 1024 KB | Output is correct |
9 | Correct | 2 ms | 1024 KB | Output is correct |
10 | Correct | 12 ms | 1068 KB | Output is correct |
11 | Correct | 3 ms | 1024 KB | Output is correct |
12 | Correct | 3 ms | 1024 KB | Output is correct |
13 | Correct | 3 ms | 1024 KB | Output is correct |
14 | Correct | 3 ms | 1124 KB | Output is correct |
15 | Correct | 3 ms | 1024 KB | Output is correct |
16 | Correct | 3 ms | 1024 KB | Output is correct |
17 | Correct | 3 ms | 1152 KB | Output is correct |
18 | Correct | 3 ms | 1152 KB | Output is correct |
19 | Correct | 3 ms | 1024 KB | Output is correct |
20 | Correct | 7 ms | 1152 KB | Output is correct |
21 | Correct | 3 ms | 1024 KB | Output is correct |
22 | Correct | 3 ms | 1152 KB | Output is correct |
23 | Correct | 4 ms | 1152 KB | Output is correct |
24 | Correct | 3 ms | 1152 KB | Output is correct |
25 | Correct | 3 ms | 1152 KB | Output is correct |
26 | Correct | 3 ms | 1024 KB | Output is correct |
27 | Correct | 4 ms | 1124 KB | Output is correct |
28 | Correct | 16 ms | 1152 KB | Output is correct |
29 | Correct | 5 ms | 1280 KB | Output is correct |
30 | Correct | 3 ms | 1152 KB | Output is correct |
31 | Correct | 4 ms | 1152 KB | Output is correct |
32 | Correct | 3 ms | 1152 KB | Output is correct |
33 | Correct | 7 ms | 1536 KB | Output is correct |
34 | Correct | 5 ms | 1408 KB | Output is correct |
35 | Correct | 10 ms | 1708 KB | Output is correct |
36 | Correct | 4 ms | 1152 KB | Output is correct |
37 | Correct | 8 ms | 1664 KB | Output is correct |
38 | Correct | 11 ms | 1920 KB | Output is correct |
39 | Correct | 10 ms | 1792 KB | Output is correct |
40 | Correct | 10 ms | 1792 KB | Output is correct |
41 | Correct | 10 ms | 1920 KB | Output is correct |
42 | Correct | 7 ms | 1792 KB | Output is correct |
43 | Correct | 8 ms | 1792 KB | Output is correct |
44 | Correct | 52 ms | 1792 KB | Output is correct |
45 | Correct | 14 ms | 2048 KB | Output is correct |
46 | Correct | 11 ms | 2048 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1024 KB | Output is correct |
2 | Correct | 2 ms | 1024 KB | Output is correct |
3 | Correct | 2 ms | 1024 KB | Output is correct |
4 | Correct | 2 ms | 1024 KB | Output is correct |
5 | Correct | 2 ms | 1024 KB | Output is correct |
6 | Correct | 3 ms | 1024 KB | Output is correct |
7 | Correct | 2 ms | 1024 KB | Output is correct |
8 | Correct | 2 ms | 1024 KB | Output is correct |
9 | Correct | 2 ms | 1024 KB | Output is correct |
10 | Correct | 3 ms | 1024 KB | Output is correct |
11 | Correct | 3 ms | 1152 KB | Output is correct |
12 | Correct | 3 ms | 1024 KB | Output is correct |
13 | Correct | 3 ms | 1024 KB | Output is correct |
14 | Correct | 3 ms | 1152 KB | Output is correct |
15 | Correct | 3 ms | 1024 KB | Output is correct |
16 | Correct | 2 ms | 1024 KB | Output is correct |
17 | Correct | 3 ms | 1152 KB | Output is correct |
18 | Correct | 3 ms | 1024 KB | Output is correct |
19 | Correct | 3 ms | 1024 KB | Output is correct |
20 | Correct | 6 ms | 1152 KB | Output is correct |
21 | Correct | 3 ms | 1024 KB | Output is correct |
22 | Correct | 2 ms | 1024 KB | Output is correct |
23 | Correct | 3 ms | 1024 KB | Output is correct |
24 | Correct | 3 ms | 1152 KB | Output is correct |
25 | Correct | 3 ms | 1152 KB | Output is correct |
26 | Correct | 3 ms | 1152 KB | Output is correct |
27 | Correct | 3 ms | 1152 KB | Output is correct |
28 | Correct | 3 ms | 1152 KB | Output is correct |
29 | Correct | 5 ms | 1280 KB | Output is correct |
30 | Correct | 4 ms | 1152 KB | Output is correct |
31 | Correct | 4 ms | 1152 KB | Output is correct |
32 | Correct | 3 ms | 1152 KB | Output is correct |
33 | Correct | 6 ms | 1536 KB | Output is correct |
34 | Correct | 6 ms | 1536 KB | Output is correct |
35 | Correct | 10 ms | 1792 KB | Output is correct |
36 | Correct | 4 ms | 1152 KB | Output is correct |
37 | Correct | 8 ms | 1664 KB | Output is correct |
38 | Correct | 10 ms | 1920 KB | Output is correct |
39 | Correct | 10 ms | 1792 KB | Output is correct |
40 | Correct | 10 ms | 1792 KB | Output is correct |
41 | Correct | 10 ms | 1920 KB | Output is correct |
42 | Correct | 8 ms | 1664 KB | Output is correct |
43 | Correct | 8 ms | 1792 KB | Output is correct |
44 | Correct | 52 ms | 1664 KB | Output is correct |
45 | Correct | 15 ms | 2020 KB | Output is correct |
46 | Correct | 12 ms | 2048 KB | Output is correct |
47 | Correct | 13 ms | 2532 KB | Output is correct |
48 | Correct | 10 ms | 2048 KB | Output is correct |
49 | Correct | 16 ms | 2048 KB | Output is correct |
50 | Correct | 8 ms | 1920 KB | Output is correct |
51 | Correct | 22 ms | 3580 KB | Output is correct |
52 | Correct | 22 ms | 3072 KB | Output is correct |
53 | Correct | 13 ms | 2688 KB | Output is correct |
54 | Correct | 4 ms | 1536 KB | Output is correct |
55 | Correct | 4 ms | 1536 KB | Output is correct |
56 | Correct | 696 ms | 3072 KB | Output is correct |
57 | Correct | 6 ms | 2048 KB | Output is correct |
58 | Correct | 690 ms | 2172 KB | Output is correct |
59 | Correct | 10 ms | 2176 KB | Output is correct |
60 | Correct | 10 ms | 2048 KB | Output is correct |
61 | Correct | 11 ms | 2176 KB | Output is correct |
62 | Correct | 14 ms | 2816 KB | Output is correct |
63 | Correct | 42 ms | 4220 KB | Output is correct |
64 | Correct | 41 ms | 4088 KB | Output is correct |
65 | Correct | 64 ms | 4092 KB | Output is correct |
66 | Correct | 165 ms | 6120 KB | Output is correct |
67 | Correct | 114 ms | 6120 KB | Output is correct |