답안 #66656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66656 2018-08-12T00:40:21 Z tincamatei Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
4 ms 1408 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 30000;

vector<pair<int, int> > graph[MAX_N];
bitset<MAX_N> doges[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(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", &doggoB[i], &doggoP[i]);
    if(i == 0)
      src = doggoB[i];
    if(i == 1)
      dest = doggoB[i];
    doges[b][p] = true;
  }

  for(int i = 0; i < m; ++i) {
    pair<int, int> doge = make_pair(doggoB[i], doggoP[i]);
    int poz = doge.first - doge.second, cost = 1;
    bool foundSimilar = false;
    while(poz >= 0 && !foundSimilar) {
      graph[doge.first].push_back(make_pair(poz, cost++));
      printf("%d %d %d\n", doge.first, poz, cost - 1);
      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++));
      printf("%d %d %d\n", doge.first, poz, cost - 1);
      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: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", &doggoB[i], &doggoP[i]);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:46:19: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
     doges[b][p] = true;
                   ^~~~
skyscraper.cpp:37:13: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
   int n, m, b, p, src, dest;
             ^
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]
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1408 KB Output isn't correct
2 Halted 0 ms 0 KB -