Submission #66648

# Submission time Handle Problem Language Result Execution time Memory
66648 2018-08-12T00:02:28 Z tincamatei Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 63800 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 30000;

vector<pair<int, int> > graph[MAX_N];
map<pair<int, int>, bool> doges;

int dist[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(dist[nod] == distNod) {
      for(auto it: graph[nod])
      if(distNod + it.second < dist[it.first]) {
        dist[it.first] = distNod + it.second;
        pq.push(make_pair(dist[it.first], it.first));
      }
    }
  }

  if(dist[dest] == 0x3f3f3f3f)
    return -1;
  else
    return dist[dest];
}

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

  for(int i = 0; i < m; ++i) {
    scanf("%d%d", &b, &p);
    if(i == 0)
      src = b;
    if(i == 1)
      dest = b;
    doges[make_pair(b, p)] = true;
  }

  for(auto it: doges) {
    pair<int, int> doge = it.first;
    if(it.second) {
      int poz = doge.first - doge.second, cost = 1;
      bool foundSimilar = false;
      while(poz >= 0 && !foundSimilar) {
        graph[doge.first].push_back(make_pair(poz, cost++));
        if(doges[make_pair(poz, doge.second)])
          foundSimilar = true;
        poz -= doge.second;
      }

      poz = doge.first + doge.second, cost = 1;
      foundSimilar = false;
      while(poz < n && !foundSimilar) {
        graph[doge.first].push_back(make_pair(poz, cost++));
        if(doges[make_pair(poz, doge.second)])
          foundSimilar = true;
        poz += doge.second;
      }
    }
  }

  printf("%d", dijkstra(n, src, dest));
  return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:38: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:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &b, &p);
     ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:72:9: warning: 'dest' may be used uninitialized in this function [-Wmaybe-uninitialized]
   printf("%d", dijkstra(n, src, dest));
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:72:9: warning: 'src' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1276 KB Output is correct
2 Correct 4 ms 1376 KB Output is correct
3 Correct 3 ms 1392 KB Output is correct
4 Correct 3 ms 1408 KB Output is correct
5 Correct 2 ms 1416 KB Output is correct
6 Correct 2 ms 1548 KB Output is correct
7 Correct 3 ms 1660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1660 KB Output is correct
2 Correct 3 ms 1660 KB Output is correct
3 Correct 3 ms 1660 KB Output is correct
4 Correct 4 ms 1660 KB Output is correct
5 Correct 3 ms 1660 KB Output is correct
6 Correct 3 ms 1720 KB Output is correct
7 Correct 3 ms 1720 KB Output is correct
8 Correct 4 ms 1720 KB Output is correct
9 Correct 3 ms 1720 KB Output is correct
10 Correct 4 ms 1808 KB Output is correct
11 Correct 5 ms 1940 KB Output is correct
12 Correct 3 ms 1940 KB Output is correct
13 Correct 3 ms 1940 KB Output is correct
14 Correct 5 ms 2136 KB Output is correct
15 Correct 5 ms 2164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2164 KB Output is correct
2 Correct 3 ms 2164 KB Output is correct
3 Correct 3 ms 2164 KB Output is correct
4 Correct 4 ms 2164 KB Output is correct
5 Correct 3 ms 2164 KB Output is correct
6 Correct 3 ms 2164 KB Output is correct
7 Correct 3 ms 2164 KB Output is correct
8 Correct 2 ms 2164 KB Output is correct
9 Correct 3 ms 2164 KB Output is correct
10 Correct 3 ms 2164 KB Output is correct
11 Correct 4 ms 2164 KB Output is correct
12 Correct 3 ms 2164 KB Output is correct
13 Correct 3 ms 2164 KB Output is correct
14 Correct 6 ms 2336 KB Output is correct
15 Correct 5 ms 2336 KB Output is correct
16 Correct 5 ms 2336 KB Output is correct
17 Correct 13 ms 3072 KB Output is correct
18 Correct 5 ms 3072 KB Output is correct
19 Correct 5 ms 3072 KB Output is correct
20 Correct 4 ms 3072 KB Output is correct
21 Correct 4 ms 3072 KB Output is correct
22 Correct 6 ms 3072 KB Output is correct
23 Correct 8 ms 3072 KB Output is correct
24 Correct 11 ms 3072 KB Output is correct
25 Correct 9 ms 3072 KB Output is correct
26 Correct 7 ms 3072 KB Output is correct
27 Correct 6 ms 3072 KB Output is correct
28 Correct 12 ms 3732 KB Output is correct
29 Correct 46 ms 6756 KB Output is correct
30 Correct 11 ms 6756 KB Output is correct
31 Correct 18 ms 6756 KB Output is correct
32 Correct 16 ms 6756 KB Output is correct
33 Correct 90 ms 11216 KB Output is correct
34 Correct 86 ms 11216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11216 KB Output is correct
2 Correct 3 ms 11216 KB Output is correct
3 Correct 3 ms 11216 KB Output is correct
4 Correct 3 ms 11216 KB Output is correct
5 Correct 4 ms 11216 KB Output is correct
6 Correct 3 ms 11216 KB Output is correct
7 Correct 3 ms 11216 KB Output is correct
8 Correct 2 ms 11216 KB Output is correct
9 Correct 3 ms 11216 KB Output is correct
10 Correct 4 ms 11216 KB Output is correct
11 Correct 5 ms 11216 KB Output is correct
12 Correct 3 ms 11216 KB Output is correct
13 Correct 3 ms 11216 KB Output is correct
14 Correct 5 ms 11216 KB Output is correct
15 Correct 5 ms 11216 KB Output is correct
16 Correct 5 ms 11216 KB Output is correct
17 Correct 10 ms 11216 KB Output is correct
18 Correct 6 ms 11216 KB Output is correct
19 Correct 5 ms 11216 KB Output is correct
20 Correct 4 ms 11216 KB Output is correct
21 Correct 4 ms 11216 KB Output is correct
22 Correct 5 ms 11216 KB Output is correct
23 Correct 7 ms 11216 KB Output is correct
24 Correct 10 ms 11216 KB Output is correct
25 Correct 8 ms 11216 KB Output is correct
26 Correct 6 ms 11216 KB Output is correct
27 Correct 5 ms 11216 KB Output is correct
28 Correct 15 ms 11216 KB Output is correct
29 Correct 48 ms 11216 KB Output is correct
30 Correct 12 ms 11216 KB Output is correct
31 Correct 18 ms 11216 KB Output is correct
32 Correct 14 ms 11216 KB Output is correct
33 Correct 82 ms 11536 KB Output is correct
34 Correct 79 ms 11536 KB Output is correct
35 Correct 79 ms 11536 KB Output is correct
36 Correct 13 ms 11536 KB Output is correct
37 Correct 130 ms 15860 KB Output is correct
38 Correct 148 ms 15860 KB Output is correct
39 Correct 136 ms 15860 KB Output is correct
40 Correct 138 ms 15860 KB Output is correct
41 Correct 143 ms 16020 KB Output is correct
42 Correct 12 ms 16020 KB Output is correct
43 Correct 11 ms 16020 KB Output is correct
44 Correct 11 ms 16020 KB Output is correct
45 Correct 752 ms 39696 KB Output is correct
46 Correct 523 ms 39776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 39776 KB Output is correct
2 Correct 3 ms 39776 KB Output is correct
3 Correct 4 ms 39776 KB Output is correct
4 Correct 3 ms 39776 KB Output is correct
5 Correct 3 ms 39776 KB Output is correct
6 Correct 3 ms 39776 KB Output is correct
7 Correct 2 ms 39776 KB Output is correct
8 Correct 3 ms 39776 KB Output is correct
9 Correct 3 ms 39776 KB Output is correct
10 Correct 4 ms 39776 KB Output is correct
11 Correct 5 ms 39776 KB Output is correct
12 Correct 4 ms 39776 KB Output is correct
13 Correct 5 ms 39776 KB Output is correct
14 Correct 6 ms 39776 KB Output is correct
15 Correct 6 ms 39776 KB Output is correct
16 Correct 4 ms 39776 KB Output is correct
17 Correct 11 ms 39776 KB Output is correct
18 Correct 6 ms 39776 KB Output is correct
19 Correct 5 ms 39776 KB Output is correct
20 Correct 4 ms 39776 KB Output is correct
21 Correct 5 ms 39776 KB Output is correct
22 Correct 5 ms 39776 KB Output is correct
23 Correct 8 ms 39776 KB Output is correct
24 Correct 11 ms 39776 KB Output is correct
25 Correct 8 ms 39776 KB Output is correct
26 Correct 7 ms 39776 KB Output is correct
27 Correct 7 ms 39776 KB Output is correct
28 Correct 14 ms 39776 KB Output is correct
29 Correct 45 ms 39776 KB Output is correct
30 Correct 12 ms 39776 KB Output is correct
31 Correct 22 ms 39776 KB Output is correct
32 Correct 13 ms 39776 KB Output is correct
33 Correct 80 ms 39776 KB Output is correct
34 Correct 83 ms 39776 KB Output is correct
35 Correct 75 ms 39776 KB Output is correct
36 Correct 16 ms 39776 KB Output is correct
37 Correct 176 ms 39776 KB Output is correct
38 Correct 139 ms 39776 KB Output is correct
39 Correct 146 ms 39776 KB Output is correct
40 Correct 152 ms 39776 KB Output is correct
41 Correct 200 ms 39776 KB Output is correct
42 Correct 11 ms 39776 KB Output is correct
43 Correct 10 ms 39776 KB Output is correct
44 Correct 14 ms 39776 KB Output is correct
45 Correct 771 ms 42392 KB Output is correct
46 Correct 654 ms 42648 KB Output is correct
47 Execution timed out 1097 ms 63800 KB Time limit exceeded
48 Halted 0 ms 0 KB -