답안 #66655

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66655 2018-08-12T00:36:25 Z tincamatei Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 76664 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 30000;

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

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) {
      if(nod == dest)
        return 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));
      }
    }
  }

  return -1;
}

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[b][p] = true;
  }

  for(int i = 0; i < n; ++i) {
    for(auto it: doges[i]) {
      pair<int, int> doge = make_pair(i, 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[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[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:37: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:40: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:73:9: warning: 'dest' may be used uninitialized in this function [-Wmaybe-uninitialized]
   printf("%d", dijkstra(n, src, dest));
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:73:9: warning: 'src' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2808 KB Output is correct
2 Correct 6 ms 2916 KB Output is correct
3 Correct 5 ms 2916 KB Output is correct
4 Correct 5 ms 2916 KB Output is correct
5 Correct 4 ms 2948 KB Output is correct
6 Correct 4 ms 2964 KB Output is correct
7 Correct 5 ms 2972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3048 KB Output is correct
2 Correct 5 ms 3048 KB Output is correct
3 Correct 5 ms 3176 KB Output is correct
4 Correct 5 ms 3176 KB Output is correct
5 Correct 5 ms 3176 KB Output is correct
6 Correct 6 ms 3176 KB Output is correct
7 Correct 5 ms 3176 KB Output is correct
8 Correct 5 ms 3176 KB Output is correct
9 Correct 4 ms 3176 KB Output is correct
10 Correct 7 ms 3176 KB Output is correct
11 Correct 9 ms 3200 KB Output is correct
12 Correct 6 ms 3200 KB Output is correct
13 Correct 4 ms 3200 KB Output is correct
14 Correct 7 ms 3312 KB Output is correct
15 Correct 8 ms 3312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3312 KB Output is correct
2 Correct 6 ms 3312 KB Output is correct
3 Correct 6 ms 3312 KB Output is correct
4 Correct 4 ms 3312 KB Output is correct
5 Correct 5 ms 3312 KB Output is correct
6 Correct 5 ms 3312 KB Output is correct
7 Correct 4 ms 3312 KB Output is correct
8 Correct 5 ms 3312 KB Output is correct
9 Correct 5 ms 3312 KB Output is correct
10 Correct 5 ms 3312 KB Output is correct
11 Correct 6 ms 3312 KB Output is correct
12 Correct 5 ms 3312 KB Output is correct
13 Correct 4 ms 3312 KB Output is correct
14 Correct 8 ms 3312 KB Output is correct
15 Correct 7 ms 3312 KB Output is correct
16 Correct 6 ms 3312 KB Output is correct
17 Correct 9 ms 3948 KB Output is correct
18 Correct 6 ms 3948 KB Output is correct
19 Correct 6 ms 3948 KB Output is correct
20 Correct 7 ms 3948 KB Output is correct
21 Correct 6 ms 3948 KB Output is correct
22 Correct 6 ms 3948 KB Output is correct
23 Correct 9 ms 3948 KB Output is correct
24 Correct 9 ms 3948 KB Output is correct
25 Correct 8 ms 3948 KB Output is correct
26 Correct 7 ms 3948 KB Output is correct
27 Correct 7 ms 3948 KB Output is correct
28 Correct 12 ms 4220 KB Output is correct
29 Correct 28 ms 6440 KB Output is correct
30 Correct 12 ms 6440 KB Output is correct
31 Correct 18 ms 6440 KB Output is correct
32 Correct 12 ms 6440 KB Output is correct
33 Correct 56 ms 9468 KB Output is correct
34 Correct 63 ms 9468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9468 KB Output is correct
2 Correct 6 ms 9468 KB Output is correct
3 Correct 6 ms 9468 KB Output is correct
4 Correct 5 ms 9468 KB Output is correct
5 Correct 5 ms 9468 KB Output is correct
6 Correct 5 ms 9468 KB Output is correct
7 Correct 4 ms 9468 KB Output is correct
8 Correct 6 ms 9468 KB Output is correct
9 Correct 6 ms 9468 KB Output is correct
10 Correct 6 ms 9468 KB Output is correct
11 Correct 9 ms 9468 KB Output is correct
12 Correct 6 ms 9468 KB Output is correct
13 Correct 5 ms 9468 KB Output is correct
14 Correct 8 ms 9468 KB Output is correct
15 Correct 8 ms 9468 KB Output is correct
16 Correct 6 ms 9468 KB Output is correct
17 Correct 12 ms 9468 KB Output is correct
18 Correct 7 ms 9468 KB Output is correct
19 Correct 7 ms 9468 KB Output is correct
20 Correct 6 ms 9468 KB Output is correct
21 Correct 7 ms 9468 KB Output is correct
22 Correct 8 ms 9468 KB Output is correct
23 Correct 8 ms 9468 KB Output is correct
24 Correct 9 ms 9468 KB Output is correct
25 Correct 7 ms 9468 KB Output is correct
26 Correct 7 ms 9468 KB Output is correct
27 Correct 7 ms 9468 KB Output is correct
28 Correct 13 ms 9468 KB Output is correct
29 Correct 26 ms 9468 KB Output is correct
30 Correct 13 ms 9468 KB Output is correct
31 Correct 16 ms 9468 KB Output is correct
32 Correct 15 ms 9468 KB Output is correct
33 Correct 61 ms 9572 KB Output is correct
34 Correct 58 ms 9572 KB Output is correct
35 Correct 56 ms 9572 KB Output is correct
36 Correct 11 ms 9572 KB Output is correct
37 Correct 147 ms 13288 KB Output is correct
38 Correct 110 ms 13288 KB Output is correct
39 Correct 118 ms 13288 KB Output is correct
40 Correct 99 ms 13288 KB Output is correct
41 Correct 141 ms 13288 KB Output is correct
42 Correct 14 ms 13288 KB Output is correct
43 Correct 12 ms 13288 KB Output is correct
44 Correct 15 ms 13288 KB Output is correct
45 Correct 394 ms 27956 KB Output is correct
46 Correct 377 ms 27956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 27956 KB Output is correct
2 Correct 5 ms 27956 KB Output is correct
3 Correct 4 ms 27956 KB Output is correct
4 Correct 4 ms 27956 KB Output is correct
5 Correct 4 ms 27956 KB Output is correct
6 Correct 5 ms 27956 KB Output is correct
7 Correct 4 ms 27956 KB Output is correct
8 Correct 5 ms 27956 KB Output is correct
9 Correct 6 ms 27956 KB Output is correct
10 Correct 6 ms 27956 KB Output is correct
11 Correct 6 ms 27956 KB Output is correct
12 Correct 5 ms 27956 KB Output is correct
13 Correct 5 ms 27956 KB Output is correct
14 Correct 7 ms 27956 KB Output is correct
15 Correct 6 ms 27956 KB Output is correct
16 Correct 5 ms 27956 KB Output is correct
17 Correct 9 ms 27956 KB Output is correct
18 Correct 7 ms 27956 KB Output is correct
19 Correct 6 ms 27956 KB Output is correct
20 Correct 5 ms 27956 KB Output is correct
21 Correct 5 ms 27956 KB Output is correct
22 Correct 6 ms 27956 KB Output is correct
23 Correct 7 ms 27956 KB Output is correct
24 Correct 11 ms 27956 KB Output is correct
25 Correct 8 ms 27956 KB Output is correct
26 Correct 7 ms 27956 KB Output is correct
27 Correct 8 ms 27956 KB Output is correct
28 Correct 15 ms 27956 KB Output is correct
29 Correct 27 ms 27956 KB Output is correct
30 Correct 11 ms 27956 KB Output is correct
31 Correct 17 ms 27956 KB Output is correct
32 Correct 14 ms 27956 KB Output is correct
33 Correct 57 ms 27956 KB Output is correct
34 Correct 62 ms 27956 KB Output is correct
35 Correct 57 ms 27956 KB Output is correct
36 Correct 13 ms 27956 KB Output is correct
37 Correct 143 ms 27956 KB Output is correct
38 Correct 111 ms 27956 KB Output is correct
39 Correct 107 ms 27956 KB Output is correct
40 Correct 110 ms 27956 KB Output is correct
41 Correct 108 ms 27956 KB Output is correct
42 Correct 16 ms 27956 KB Output is correct
43 Correct 18 ms 27956 KB Output is correct
44 Correct 11 ms 27956 KB Output is correct
45 Correct 393 ms 27956 KB Output is correct
46 Correct 447 ms 27956 KB Output is correct
47 Correct 828 ms 43672 KB Output is correct
48 Correct 162 ms 43672 KB Output is correct
49 Correct 90 ms 43672 KB Output is correct
50 Correct 96 ms 43672 KB Output is correct
51 Correct 261 ms 43672 KB Output is correct
52 Correct 301 ms 43672 KB Output is correct
53 Correct 63 ms 43672 KB Output is correct
54 Correct 13 ms 43672 KB Output is correct
55 Correct 22 ms 43672 KB Output is correct
56 Correct 38 ms 43672 KB Output is correct
57 Correct 295 ms 43672 KB Output is correct
58 Correct 35 ms 43672 KB Output is correct
59 Correct 55 ms 43672 KB Output is correct
60 Correct 72 ms 43672 KB Output is correct
61 Correct 75 ms 43672 KB Output is correct
62 Correct 451 ms 43672 KB Output is correct
63 Execution timed out 1070 ms 76664 KB Time limit exceeded
64 Halted 0 ms 0 KB -