Submission #537393

# Submission time Handle Problem Language Result Execution time Memory
537393 2022-03-15T04:21:47 Z OrazB Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
774 ms 63468 KB
#include <bits/stdc++.h>
using namespace std;

int n, m;
int pw[100005];
int pos[100005];
vector <int> doges[100005];

int dist[50005][300];

priority_queue<pair<int,pair<int,int> > > pq;

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &pos[i], &pw[i]);
    doges[pos[i]].push_back(i);
  }

  for (int i = 0; i <= 50000; i++) {
    for (int j = 0; j < 300; j++) {
      dist[i][j] = 1000000000;
    }
  }
  pq.push(make_pair(0, make_pair(pos[0], 0)));
  dist[pos[0]][0] = 0;
  int limit = (int) sqrt(n);
  int res = 1000000000;

  while (!pq.empty()) {
    pair<int,pair<int,int> > now = pq.top();
    pq.pop();
    int posnow = now.second.first;
    int distnow = -now.first;
    if (posnow == pos[1]) {
      res = min(res, distnow);
    }
    int pownow = now.second.second;
    if (pownow == 0) {
      for (int i = 0; i < (int)doges[posnow].size(); i++) {
        if (pw[doges[posnow][i]] <= limit) {
          pair <int,pair<int,int> > nxt;
          if (dist[posnow][pw[doges[posnow][i]]] > distnow) {
            dist[posnow][pw[doges[posnow][i]]] = distnow;
            int distnext = distnow;
            pq.push(make_pair(-distnext, make_pair(posnow, pw[doges[posnow][i]])));
          }
        } else {
          int powernow = pw[doges[posnow][i]];
          for (int j = 1; posnow - j*powernow >= 0; ++j) {
            int posnext = posnow - j*powernow;
            int distnext = distnow + j;
            if (dist[posnext][0] > distnext) {
              dist[posnext][0] = distnext;
              pq.push(make_pair(-distnext, make_pair(posnext, 0)));
            }
          }
          for (int j = 1; posnow + j*powernow < n; ++j) {
            int posnext = posnow + j*powernow;
            int distnext = distnow + j;
            if (dist[posnext][0] > distnext) {
              dist[posnext][0] = distnext;
              pq.push(make_pair(-distnext, make_pair(posnext, 0)));
            }
          }
        }
      }
    } else {
      if (dist[posnow][0] > distnow) {
        dist[posnow][0] = distnow;
        pq.push(make_pair(-dist[posnow][0], make_pair(posnow, 0)));
      }
      if (posnow + pownow < n && dist[posnow + pownow][pownow] > dist[posnow][pownow] + 1) {
        int distnext = dist[posnow][pownow] + 1;
        int posnext = posnow + pownow;
        dist[posnext][pownow] = dist[posnow][pownow] + 1;
        pq.push(make_pair(-distnext, make_pair(posnext, pownow)));
      }
      if (posnow - pownow >= 0 && dist[posnow - pownow][pownow] > dist[posnow][pownow] + 1) {
        int distnext = dist[posnow][pownow] + 1;
        int posnext = posnow - pownow;
        dist[posnext][pownow] = dist[posnow][pownow] + 1;
        pq.push(make_pair(-distnext, make_pair(posnext, pownow)));
      }
    }
  }
  if (res == 1000000000) res = -1;
  printf("%d\n",res);
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%d %d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d %d", &pos[i], &pw[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 31 ms 61284 KB Output is correct
2 Correct 31 ms 61252 KB Output is correct
3 Correct 37 ms 61284 KB Output is correct
4 Correct 37 ms 61280 KB Output is correct
5 Correct 32 ms 61320 KB Output is correct
6 Correct 33 ms 61276 KB Output is correct
7 Correct 31 ms 61268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 61284 KB Output is correct
2 Correct 31 ms 61248 KB Output is correct
3 Correct 32 ms 61312 KB Output is correct
4 Correct 34 ms 61344 KB Output is correct
5 Correct 31 ms 61268 KB Output is correct
6 Correct 31 ms 61264 KB Output is correct
7 Correct 37 ms 61272 KB Output is correct
8 Correct 33 ms 61268 KB Output is correct
9 Correct 31 ms 61268 KB Output is correct
10 Correct 30 ms 61268 KB Output is correct
11 Correct 37 ms 61320 KB Output is correct
12 Correct 35 ms 61384 KB Output is correct
13 Correct 32 ms 61356 KB Output is correct
14 Correct 34 ms 61352 KB Output is correct
15 Correct 32 ms 61388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 61268 KB Output is correct
2 Correct 31 ms 61372 KB Output is correct
3 Correct 32 ms 61272 KB Output is correct
4 Correct 32 ms 61248 KB Output is correct
5 Correct 30 ms 61356 KB Output is correct
6 Correct 33 ms 61296 KB Output is correct
7 Correct 31 ms 61340 KB Output is correct
8 Correct 31 ms 61352 KB Output is correct
9 Correct 31 ms 61268 KB Output is correct
10 Correct 31 ms 61384 KB Output is correct
11 Correct 33 ms 61388 KB Output is correct
12 Correct 34 ms 61396 KB Output is correct
13 Correct 31 ms 61388 KB Output is correct
14 Correct 32 ms 61360 KB Output is correct
15 Correct 33 ms 61388 KB Output is correct
16 Correct 31 ms 61276 KB Output is correct
17 Correct 31 ms 61304 KB Output is correct
18 Correct 32 ms 61388 KB Output is correct
19 Correct 33 ms 61324 KB Output is correct
20 Correct 32 ms 61388 KB Output is correct
21 Correct 35 ms 61336 KB Output is correct
22 Correct 37 ms 61396 KB Output is correct
23 Correct 33 ms 61380 KB Output is correct
24 Correct 33 ms 61412 KB Output is correct
25 Correct 32 ms 61304 KB Output is correct
26 Correct 32 ms 61396 KB Output is correct
27 Correct 32 ms 61396 KB Output is correct
28 Correct 32 ms 61352 KB Output is correct
29 Correct 38 ms 61328 KB Output is correct
30 Correct 36 ms 61268 KB Output is correct
31 Correct 35 ms 61396 KB Output is correct
32 Correct 33 ms 61380 KB Output is correct
33 Correct 43 ms 61396 KB Output is correct
34 Correct 40 ms 61464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 61256 KB Output is correct
2 Correct 37 ms 61308 KB Output is correct
3 Correct 32 ms 61304 KB Output is correct
4 Correct 31 ms 61320 KB Output is correct
5 Correct 32 ms 61296 KB Output is correct
6 Correct 31 ms 61352 KB Output is correct
7 Correct 35 ms 61280 KB Output is correct
8 Correct 33 ms 61272 KB Output is correct
9 Correct 34 ms 61268 KB Output is correct
10 Correct 31 ms 61276 KB Output is correct
11 Correct 31 ms 61340 KB Output is correct
12 Correct 31 ms 61280 KB Output is correct
13 Correct 33 ms 61360 KB Output is correct
14 Correct 35 ms 61360 KB Output is correct
15 Correct 31 ms 61268 KB Output is correct
16 Correct 31 ms 61340 KB Output is correct
17 Correct 33 ms 61292 KB Output is correct
18 Correct 32 ms 61396 KB Output is correct
19 Correct 34 ms 61392 KB Output is correct
20 Correct 33 ms 61388 KB Output is correct
21 Correct 32 ms 61320 KB Output is correct
22 Correct 30 ms 61260 KB Output is correct
23 Correct 31 ms 61300 KB Output is correct
24 Correct 32 ms 61372 KB Output is correct
25 Correct 32 ms 61312 KB Output is correct
26 Correct 32 ms 61368 KB Output is correct
27 Correct 32 ms 61296 KB Output is correct
28 Correct 35 ms 61392 KB Output is correct
29 Correct 41 ms 61316 KB Output is correct
30 Correct 33 ms 61332 KB Output is correct
31 Correct 36 ms 61296 KB Output is correct
32 Correct 34 ms 61320 KB Output is correct
33 Correct 40 ms 61384 KB Output is correct
34 Correct 42 ms 61388 KB Output is correct
35 Correct 42 ms 61784 KB Output is correct
36 Correct 33 ms 61396 KB Output is correct
37 Correct 49 ms 61760 KB Output is correct
38 Correct 45 ms 61900 KB Output is correct
39 Correct 46 ms 61952 KB Output is correct
40 Correct 46 ms 61904 KB Output is correct
41 Correct 47 ms 61904 KB Output is correct
42 Correct 36 ms 61804 KB Output is correct
43 Correct 40 ms 61900 KB Output is correct
44 Correct 36 ms 61772 KB Output is correct
45 Correct 46 ms 61828 KB Output is correct
46 Correct 46 ms 61900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 61268 KB Output is correct
2 Correct 32 ms 61264 KB Output is correct
3 Correct 30 ms 61296 KB Output is correct
4 Correct 31 ms 61308 KB Output is correct
5 Correct 33 ms 61268 KB Output is correct
6 Correct 33 ms 61260 KB Output is correct
7 Correct 34 ms 61388 KB Output is correct
8 Correct 32 ms 61296 KB Output is correct
9 Correct 32 ms 61312 KB Output is correct
10 Correct 31 ms 61284 KB Output is correct
11 Correct 31 ms 61280 KB Output is correct
12 Correct 32 ms 61368 KB Output is correct
13 Correct 31 ms 61292 KB Output is correct
14 Correct 31 ms 61288 KB Output is correct
15 Correct 31 ms 61384 KB Output is correct
16 Correct 36 ms 61252 KB Output is correct
17 Correct 33 ms 61408 KB Output is correct
18 Correct 33 ms 61280 KB Output is correct
19 Correct 31 ms 61272 KB Output is correct
20 Correct 31 ms 61444 KB Output is correct
21 Correct 31 ms 61396 KB Output is correct
22 Correct 33 ms 61392 KB Output is correct
23 Correct 32 ms 61316 KB Output is correct
24 Correct 34 ms 61388 KB Output is correct
25 Correct 31 ms 61360 KB Output is correct
26 Correct 33 ms 61364 KB Output is correct
27 Correct 32 ms 61328 KB Output is correct
28 Correct 37 ms 61396 KB Output is correct
29 Correct 38 ms 61388 KB Output is correct
30 Correct 34 ms 61268 KB Output is correct
31 Correct 38 ms 61312 KB Output is correct
32 Correct 32 ms 61340 KB Output is correct
33 Correct 40 ms 61352 KB Output is correct
34 Correct 40 ms 61480 KB Output is correct
35 Correct 40 ms 61856 KB Output is correct
36 Correct 35 ms 61420 KB Output is correct
37 Correct 46 ms 61748 KB Output is correct
38 Correct 45 ms 61876 KB Output is correct
39 Correct 48 ms 61900 KB Output is correct
40 Correct 46 ms 61948 KB Output is correct
41 Correct 47 ms 61872 KB Output is correct
42 Correct 36 ms 61860 KB Output is correct
43 Correct 38 ms 61812 KB Output is correct
44 Correct 36 ms 61780 KB Output is correct
45 Correct 47 ms 61908 KB Output is correct
46 Correct 46 ms 61836 KB Output is correct
47 Correct 103 ms 62324 KB Output is correct
48 Correct 38 ms 61924 KB Output is correct
49 Correct 37 ms 62036 KB Output is correct
50 Correct 35 ms 61996 KB Output is correct
51 Correct 84 ms 62784 KB Output is correct
52 Correct 80 ms 62692 KB Output is correct
53 Correct 45 ms 62100 KB Output is correct
54 Correct 32 ms 61260 KB Output is correct
55 Correct 33 ms 61288 KB Output is correct
56 Correct 40 ms 62472 KB Output is correct
57 Correct 93 ms 61388 KB Output is correct
58 Correct 41 ms 61896 KB Output is correct
59 Correct 41 ms 61836 KB Output is correct
60 Correct 45 ms 61860 KB Output is correct
61 Correct 40 ms 61744 KB Output is correct
62 Correct 65 ms 62416 KB Output is correct
63 Correct 74 ms 62664 KB Output is correct
64 Correct 79 ms 62692 KB Output is correct
65 Correct 280 ms 63468 KB Output is correct
66 Correct 735 ms 63460 KB Output is correct
67 Correct 774 ms 63464 KB Output is correct