Submission #351206

# Submission time Handle Problem Language Result Execution time Memory
351206 2021-01-19T16:20:37 Z Tony1234 Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
127 ms 7772 KB
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int MM = 30030, INF = 0x3f3f3f3f;
set<int> adj[MM];
int dis[MM];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> cur;
int main(){
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  for(int i=0; i < MM; i++)dis[i] = INF;
  int num, paths, a, b; cin >> num >> paths;
  int start = -1, dest = -1;
  for(int i=0; i < paths; i++){
    cin >> a >> b;
    if(i == 0){
      start = a;
    }else if(i==1){
      dest = a;
    }
    adj[a].insert(b);
  }
  cur.push({0, start});
  dis[start] = 0;
  while(!cur.empty()){
    pii e = cur.top(); cur.pop();
    int cit = e.second, price=  e.first;
    if(cit == dest){
      cout << dis[cit]<<'\n';
      return 0;
    }
    if(dis[cit] < price)continue;
    for(int u: adj[cit]){
      //go up
      for(int i=1; cit + i*u < num; i++){
        int nn = cit+i*u;
        int add= price+i;
        if(dis[nn] > add){
            dis[nn] = add;
            cur.push({add, nn});
        }
        if(adj[nn].count(u))break;
      }
      //go down
      for(int i=1; cit-i*u >= 0; i++){
          int nn = cit-i*u;
          int add = price+i;
          if(dis[nn]>add){
          dis[nn] = add; cur.push({add, nn});
        }
        if(adj[nn].count(u))break;
      }
    }
  }
  cout << -1;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1900 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 2 ms 1900 KB Output is correct
4 Correct 2 ms 1900 KB Output is correct
5 Correct 2 ms 1900 KB Output is correct
6 Correct 1 ms 1900 KB Output is correct
7 Correct 2 ms 2028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1900 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 1 ms 1900 KB Output is correct
4 Correct 1 ms 1900 KB Output is correct
5 Correct 1 ms 1900 KB Output is correct
6 Correct 1 ms 1900 KB Output is correct
7 Correct 2 ms 1900 KB Output is correct
8 Correct 1 ms 1900 KB Output is correct
9 Correct 1 ms 1900 KB Output is correct
10 Correct 2 ms 1900 KB Output is correct
11 Correct 2 ms 1900 KB Output is correct
12 Correct 3 ms 1900 KB Output is correct
13 Correct 2 ms 1900 KB Output is correct
14 Correct 2 ms 2028 KB Output is correct
15 Correct 2 ms 2028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1900 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 1 ms 1900 KB Output is correct
4 Correct 2 ms 1900 KB Output is correct
5 Correct 1 ms 1900 KB Output is correct
6 Correct 2 ms 1900 KB Output is correct
7 Correct 1 ms 1900 KB Output is correct
8 Correct 1 ms 1900 KB Output is correct
9 Correct 2 ms 1900 KB Output is correct
10 Correct 2 ms 1908 KB Output is correct
11 Correct 3 ms 1900 KB Output is correct
12 Correct 2 ms 1900 KB Output is correct
13 Correct 2 ms 1900 KB Output is correct
14 Correct 3 ms 2028 KB Output is correct
15 Correct 2 ms 2028 KB Output is correct
16 Correct 2 ms 1900 KB Output is correct
17 Correct 2 ms 2028 KB Output is correct
18 Correct 2 ms 1900 KB Output is correct
19 Correct 2 ms 1900 KB Output is correct
20 Correct 2 ms 2028 KB Output is correct
21 Correct 2 ms 1900 KB Output is correct
22 Correct 2 ms 1900 KB Output is correct
23 Correct 2 ms 1900 KB Output is correct
24 Correct 3 ms 2028 KB Output is correct
25 Correct 3 ms 2028 KB Output is correct
26 Correct 2 ms 1900 KB Output is correct
27 Correct 2 ms 1900 KB Output is correct
28 Correct 2 ms 2028 KB Output is correct
29 Correct 4 ms 2156 KB Output is correct
30 Correct 2 ms 2028 KB Output is correct
31 Correct 3 ms 2028 KB Output is correct
32 Correct 2 ms 2028 KB Output is correct
33 Correct 5 ms 2412 KB Output is correct
34 Correct 4 ms 2412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2048 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 1 ms 1900 KB Output is correct
4 Correct 2 ms 1916 KB Output is correct
5 Correct 1 ms 1900 KB Output is correct
6 Correct 1 ms 1900 KB Output is correct
7 Correct 1 ms 1900 KB Output is correct
8 Correct 1 ms 1900 KB Output is correct
9 Correct 2 ms 1900 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 2 ms 1900 KB Output is correct
12 Correct 2 ms 1900 KB Output is correct
13 Correct 2 ms 1900 KB Output is correct
14 Correct 2 ms 2028 KB Output is correct
15 Correct 2 ms 2028 KB Output is correct
16 Correct 2 ms 1900 KB Output is correct
17 Correct 2 ms 2028 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 2 ms 1900 KB Output is correct
20 Correct 2 ms 2028 KB Output is correct
21 Correct 2 ms 1900 KB Output is correct
22 Correct 2 ms 1900 KB Output is correct
23 Correct 2 ms 1900 KB Output is correct
24 Correct 3 ms 2028 KB Output is correct
25 Correct 2 ms 2028 KB Output is correct
26 Correct 2 ms 1900 KB Output is correct
27 Correct 2 ms 1900 KB Output is correct
28 Correct 2 ms 2028 KB Output is correct
29 Correct 4 ms 2156 KB Output is correct
30 Correct 2 ms 2028 KB Output is correct
31 Correct 3 ms 2048 KB Output is correct
32 Correct 2 ms 2028 KB Output is correct
33 Correct 6 ms 2412 KB Output is correct
34 Correct 4 ms 2412 KB Output is correct
35 Correct 15 ms 3308 KB Output is correct
36 Correct 3 ms 2156 KB Output is correct
37 Correct 13 ms 3052 KB Output is correct
38 Correct 15 ms 3564 KB Output is correct
39 Correct 12 ms 3564 KB Output is correct
40 Correct 12 ms 3564 KB Output is correct
41 Correct 13 ms 3692 KB Output is correct
42 Correct 6 ms 2304 KB Output is correct
43 Correct 6 ms 2156 KB Output is correct
44 Correct 6 ms 2156 KB Output is correct
45 Correct 19 ms 3820 KB Output is correct
46 Correct 17 ms 3948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2028 KB Output is correct
2 Correct 2 ms 2028 KB Output is correct
3 Correct 1 ms 1900 KB Output is correct
4 Correct 2 ms 1900 KB Output is correct
5 Correct 1 ms 1900 KB Output is correct
6 Correct 1 ms 1900 KB Output is correct
7 Correct 1 ms 1900 KB Output is correct
8 Correct 1 ms 1900 KB Output is correct
9 Correct 1 ms 1900 KB Output is correct
10 Correct 2 ms 1900 KB Output is correct
11 Correct 2 ms 1900 KB Output is correct
12 Correct 2 ms 1900 KB Output is correct
13 Correct 2 ms 2044 KB Output is correct
14 Correct 2 ms 2028 KB Output is correct
15 Correct 2 ms 2048 KB Output is correct
16 Correct 2 ms 2028 KB Output is correct
17 Correct 2 ms 2028 KB Output is correct
18 Correct 2 ms 1900 KB Output is correct
19 Correct 2 ms 1900 KB Output is correct
20 Correct 2 ms 2028 KB Output is correct
21 Correct 2 ms 1900 KB Output is correct
22 Correct 2 ms 1900 KB Output is correct
23 Correct 2 ms 1900 KB Output is correct
24 Correct 3 ms 2028 KB Output is correct
25 Correct 3 ms 2048 KB Output is correct
26 Correct 3 ms 1900 KB Output is correct
27 Correct 2 ms 2028 KB Output is correct
28 Correct 3 ms 2028 KB Output is correct
29 Correct 5 ms 2216 KB Output is correct
30 Correct 3 ms 2028 KB Output is correct
31 Correct 3 ms 2028 KB Output is correct
32 Correct 2 ms 2028 KB Output is correct
33 Correct 5 ms 2412 KB Output is correct
34 Correct 5 ms 2412 KB Output is correct
35 Correct 15 ms 3308 KB Output is correct
36 Correct 3 ms 2156 KB Output is correct
37 Correct 14 ms 3052 KB Output is correct
38 Correct 14 ms 3564 KB Output is correct
39 Correct 16 ms 3564 KB Output is correct
40 Correct 12 ms 3564 KB Output is correct
41 Correct 14 ms 3692 KB Output is correct
42 Correct 6 ms 2028 KB Output is correct
43 Correct 9 ms 2156 KB Output is correct
44 Correct 6 ms 2156 KB Output is correct
45 Correct 20 ms 3820 KB Output is correct
46 Correct 17 ms 3820 KB Output is correct
47 Correct 20 ms 3816 KB Output is correct
48 Correct 9 ms 3180 KB Output is correct
49 Correct 11 ms 3052 KB Output is correct
50 Correct 7 ms 2668 KB Output is correct
51 Correct 29 ms 4200 KB Output is correct
52 Correct 25 ms 4200 KB Output is correct
53 Correct 13 ms 3820 KB Output is correct
54 Correct 3 ms 2156 KB Output is correct
55 Correct 4 ms 2156 KB Output is correct
56 Correct 12 ms 3436 KB Output is correct
57 Correct 3 ms 2412 KB Output is correct
58 Correct 8 ms 2284 KB Output is correct
59 Correct 9 ms 2284 KB Output is correct
60 Correct 9 ms 2284 KB Output is correct
61 Correct 9 ms 2540 KB Output is correct
62 Correct 17 ms 3564 KB Output is correct
63 Correct 53 ms 5856 KB Output is correct
64 Correct 54 ms 5728 KB Output is correct
65 Correct 64 ms 5728 KB Output is correct
66 Correct 127 ms 7772 KB Output is correct
67 Correct 84 ms 7772 KB Output is correct