Submission #66658

# Submission time Handle Problem Language Result Execution time Memory
66658 2018-08-12T00:56:53 Z tincamatei Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
201 ms 112820 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 30000;

bitset<MAX_N> doges[MAX_N];
vector<int> scrapers[MAX_N];

int dist[MAX_N];
int doggoB[MAX_N], doggoP[MAX_N];

int dijkstra(int n, int src, int dest) {
  priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;
  memset(dist, 0x3f3f3f3f, sizeof(dist));
  dist[src] = 0;
  pq.push(make_pair(0, src));
  while(!pq.empty()) {
    int nod = pq.top().second, distNod = pq.top().first;
    pq.pop();

    if(distNod == dist[nod]) {
      if(nod == dest)
        return distNod;

      for(auto dog: scrapers[nod]) {
        int it = nod - dog, cost = 1;
        while(it >= 0) {
          if(dist[nod] + cost < dist[it]) {
            dist[it] = dist[nod] + cost;
            pq.push(make_pair(dist[it], it));
          }
          if(doges[it][dog])
            break;

          it -= dog;
          ++cost;
        }
        it = nod + dog, cost = 1;
        while(it < n) {
          if(dist[nod] + cost < dist[it]) {
            dist[it] = dist[nod] + cost;
            pq.push(make_pair(dist[it], it));
          }
          if(doges[it][dog])
            break;
          it += dog;
          ++cost;
        }
      }
    }
  }

  return -1;
}

int main() {
  int n, m, b, p;
  scanf("%d%d", &n, &m);

  for(int i = 0; i < m; ++i) {
    scanf("%d%d", &b, &p);
    doggoB[i] = b;
    doggoP[i] = p;
    if(!doges[b][p]) {
      scrapers[b].push_back(p);
      doges[b][p] = true;
    }
  }

  printf("%d", dijkstra(n, doggoB[0], doggoB[1]));
  return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &b, &p);
     ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 2 ms 1144 KB Output is correct
3 Correct 3 ms 1196 KB Output is correct
4 Correct 3 ms 1196 KB Output is correct
5 Correct 3 ms 1228 KB Output is correct
6 Correct 3 ms 1276 KB Output is correct
7 Correct 4 ms 1284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1284 KB Output is correct
2 Correct 4 ms 1284 KB Output is correct
3 Correct 3 ms 1308 KB Output is correct
4 Correct 3 ms 1312 KB Output is correct
5 Correct 3 ms 1444 KB Output is correct
6 Correct 3 ms 1444 KB Output is correct
7 Correct 3 ms 1444 KB Output is correct
8 Correct 4 ms 1444 KB Output is correct
9 Correct 4 ms 1516 KB Output is correct
10 Correct 4 ms 1720 KB Output is correct
11 Correct 4 ms 1772 KB Output is correct
12 Correct 4 ms 1772 KB Output is correct
13 Correct 4 ms 1800 KB Output is correct
14 Correct 4 ms 1800 KB Output is correct
15 Correct 4 ms 1800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1800 KB Output is correct
2 Correct 2 ms 1800 KB Output is correct
3 Correct 4 ms 1800 KB Output is correct
4 Correct 3 ms 1800 KB Output is correct
5 Correct 3 ms 1800 KB Output is correct
6 Correct 2 ms 1800 KB Output is correct
7 Correct 3 ms 1800 KB Output is correct
8 Correct 3 ms 1800 KB Output is correct
9 Correct 3 ms 1800 KB Output is correct
10 Correct 3 ms 1800 KB Output is correct
11 Correct 4 ms 1800 KB Output is correct
12 Correct 4 ms 1800 KB Output is correct
13 Correct 5 ms 1800 KB Output is correct
14 Correct 4 ms 1800 KB Output is correct
15 Correct 3 ms 1800 KB Output is correct
16 Correct 4 ms 2172 KB Output is correct
17 Correct 8 ms 3984 KB Output is correct
18 Correct 6 ms 4416 KB Output is correct
19 Correct 5 ms 4416 KB Output is correct
20 Correct 13 ms 8828 KB Output is correct
21 Correct 5 ms 8828 KB Output is correct
22 Correct 8 ms 8828 KB Output is correct
23 Correct 9 ms 8828 KB Output is correct
24 Correct 12 ms 8828 KB Output is correct
25 Correct 10 ms 8828 KB Output is correct
26 Correct 5 ms 8828 KB Output is correct
27 Correct 6 ms 8828 KB Output is correct
28 Correct 12 ms 8828 KB Output is correct
29 Correct 6 ms 8828 KB Output is correct
30 Correct 5 ms 8828 KB Output is correct
31 Correct 6 ms 8828 KB Output is correct
32 Correct 5 ms 8828 KB Output is correct
33 Correct 7 ms 8828 KB Output is correct
34 Correct 8 ms 8828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8828 KB Output is correct
2 Correct 4 ms 8828 KB Output is correct
3 Correct 4 ms 8828 KB Output is correct
4 Correct 3 ms 8828 KB Output is correct
5 Correct 3 ms 8828 KB Output is correct
6 Correct 4 ms 8828 KB Output is correct
7 Correct 4 ms 8828 KB Output is correct
8 Correct 4 ms 8828 KB Output is correct
9 Correct 4 ms 8828 KB Output is correct
10 Correct 3 ms 8828 KB Output is correct
11 Correct 5 ms 8828 KB Output is correct
12 Correct 4 ms 8828 KB Output is correct
13 Correct 4 ms 8828 KB Output is correct
14 Correct 4 ms 8828 KB Output is correct
15 Correct 4 ms 8828 KB Output is correct
16 Correct 6 ms 8828 KB Output is correct
17 Correct 8 ms 8828 KB Output is correct
18 Correct 7 ms 8828 KB Output is correct
19 Correct 5 ms 8828 KB Output is correct
20 Correct 12 ms 8828 KB Output is correct
21 Correct 6 ms 8828 KB Output is correct
22 Correct 6 ms 8828 KB Output is correct
23 Correct 10 ms 8828 KB Output is correct
24 Correct 11 ms 8828 KB Output is correct
25 Correct 11 ms 8828 KB Output is correct
26 Correct 7 ms 8828 KB Output is correct
27 Correct 5 ms 8828 KB Output is correct
28 Correct 13 ms 8828 KB Output is correct
29 Correct 8 ms 8828 KB Output is correct
30 Correct 6 ms 8828 KB Output is correct
31 Correct 7 ms 8828 KB Output is correct
32 Correct 7 ms 8828 KB Output is correct
33 Correct 9 ms 8828 KB Output is correct
34 Correct 8 ms 8828 KB Output is correct
35 Correct 20 ms 8828 KB Output is correct
36 Correct 10 ms 8828 KB Output is correct
37 Correct 20 ms 8956 KB Output is correct
38 Correct 26 ms 9340 KB Output is correct
39 Correct 22 ms 9340 KB Output is correct
40 Correct 23 ms 9340 KB Output is correct
41 Correct 29 ms 9340 KB Output is correct
42 Correct 12 ms 9340 KB Output is correct
43 Correct 17 ms 9340 KB Output is correct
44 Correct 17 ms 9340 KB Output is correct
45 Correct 16 ms 9340 KB Output is correct
46 Correct 15 ms 9340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9340 KB Output is correct
2 Correct 3 ms 9340 KB Output is correct
3 Correct 3 ms 9340 KB Output is correct
4 Correct 4 ms 9340 KB Output is correct
5 Correct 3 ms 9340 KB Output is correct
6 Correct 3 ms 9340 KB Output is correct
7 Correct 3 ms 9340 KB Output is correct
8 Correct 3 ms 9340 KB Output is correct
9 Correct 4 ms 9340 KB Output is correct
10 Correct 4 ms 9340 KB Output is correct
11 Correct 5 ms 9340 KB Output is correct
12 Correct 4 ms 9340 KB Output is correct
13 Correct 4 ms 9340 KB Output is correct
14 Correct 4 ms 9340 KB Output is correct
15 Correct 5 ms 9340 KB Output is correct
16 Correct 5 ms 9340 KB Output is correct
17 Correct 9 ms 9340 KB Output is correct
18 Correct 7 ms 9340 KB Output is correct
19 Correct 5 ms 9340 KB Output is correct
20 Correct 11 ms 9340 KB Output is correct
21 Correct 5 ms 9340 KB Output is correct
22 Correct 6 ms 9340 KB Output is correct
23 Correct 8 ms 9340 KB Output is correct
24 Correct 11 ms 9340 KB Output is correct
25 Correct 9 ms 9340 KB Output is correct
26 Correct 5 ms 9340 KB Output is correct
27 Correct 6 ms 9340 KB Output is correct
28 Correct 15 ms 9340 KB Output is correct
29 Correct 8 ms 9340 KB Output is correct
30 Correct 7 ms 9340 KB Output is correct
31 Correct 8 ms 9340 KB Output is correct
32 Correct 5 ms 9340 KB Output is correct
33 Correct 9 ms 9340 KB Output is correct
34 Correct 7 ms 9340 KB Output is correct
35 Correct 19 ms 9340 KB Output is correct
36 Correct 9 ms 9340 KB Output is correct
37 Correct 24 ms 9340 KB Output is correct
38 Correct 22 ms 9340 KB Output is correct
39 Correct 22 ms 9340 KB Output is correct
40 Correct 21 ms 9340 KB Output is correct
41 Correct 22 ms 9340 KB Output is correct
42 Correct 11 ms 9340 KB Output is correct
43 Correct 11 ms 9340 KB Output is correct
44 Correct 16 ms 9340 KB Output is correct
45 Correct 15 ms 9340 KB Output is correct
46 Correct 16 ms 9340 KB Output is correct
47 Correct 69 ms 42364 KB Output is correct
48 Correct 75 ms 57724 KB Output is correct
49 Correct 79 ms 57724 KB Output is correct
50 Correct 61 ms 57724 KB Output is correct
51 Correct 143 ms 75736 KB Output is correct
52 Correct 139 ms 76180 KB Output is correct
53 Correct 103 ms 76180 KB Output is correct
54 Correct 21 ms 76180 KB Output is correct
55 Correct 26 ms 76180 KB Output is correct
56 Correct 152 ms 112820 KB Output is correct
57 Correct 27 ms 112820 KB Output is correct
58 Correct 39 ms 112820 KB Output is correct
59 Correct 46 ms 112820 KB Output is correct
60 Correct 46 ms 112820 KB Output is correct
61 Correct 38 ms 112820 KB Output is correct
62 Correct 159 ms 112820 KB Output is correct
63 Correct 97 ms 112820 KB Output is correct
64 Correct 114 ms 112820 KB Output is correct
65 Correct 134 ms 112820 KB Output is correct
66 Correct 201 ms 112820 KB Output is correct
67 Correct 179 ms 112820 KB Output is correct