Submission #260036

# Submission time Handle Problem Language Result Execution time Memory
260036 2020-08-09T04:57:17 Z pure_mem Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
930 ms 63744 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]
   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]
     scanf("%d %d", &pos[i], &pw[i]);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 37 ms 61432 KB Output is correct
2 Correct 40 ms 61408 KB Output is correct
3 Correct 37 ms 61436 KB Output is correct
4 Correct 39 ms 61432 KB Output is correct
5 Correct 39 ms 61560 KB Output is correct
6 Correct 37 ms 61440 KB Output is correct
7 Correct 37 ms 61432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 61304 KB Output is correct
2 Correct 37 ms 61440 KB Output is correct
3 Correct 42 ms 61432 KB Output is correct
4 Correct 38 ms 61432 KB Output is correct
5 Correct 38 ms 61304 KB Output is correct
6 Correct 37 ms 61432 KB Output is correct
7 Correct 37 ms 61444 KB Output is correct
8 Correct 38 ms 61560 KB Output is correct
9 Correct 37 ms 61432 KB Output is correct
10 Correct 39 ms 61432 KB Output is correct
11 Correct 37 ms 61432 KB Output is correct
12 Correct 38 ms 61432 KB Output is correct
13 Correct 40 ms 61432 KB Output is correct
14 Correct 40 ms 61560 KB Output is correct
15 Correct 37 ms 61440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 61440 KB Output is correct
2 Correct 38 ms 61440 KB Output is correct
3 Correct 37 ms 61432 KB Output is correct
4 Correct 38 ms 61440 KB Output is correct
5 Correct 38 ms 61432 KB Output is correct
6 Correct 37 ms 61432 KB Output is correct
7 Correct 38 ms 61432 KB Output is correct
8 Correct 37 ms 61440 KB Output is correct
9 Correct 38 ms 61432 KB Output is correct
10 Correct 43 ms 61432 KB Output is correct
11 Correct 38 ms 61432 KB Output is correct
12 Correct 38 ms 61432 KB Output is correct
13 Correct 39 ms 61432 KB Output is correct
14 Correct 43 ms 61432 KB Output is correct
15 Correct 37 ms 61440 KB Output is correct
16 Correct 37 ms 61432 KB Output is correct
17 Correct 39 ms 61432 KB Output is correct
18 Correct 37 ms 61408 KB Output is correct
19 Correct 38 ms 61432 KB Output is correct
20 Correct 38 ms 61432 KB Output is correct
21 Correct 43 ms 61432 KB Output is correct
22 Correct 40 ms 61432 KB Output is correct
23 Correct 44 ms 61432 KB Output is correct
24 Correct 39 ms 61440 KB Output is correct
25 Correct 39 ms 61368 KB Output is correct
26 Correct 38 ms 61432 KB Output is correct
27 Correct 38 ms 61432 KB Output is correct
28 Correct 42 ms 61560 KB Output is correct
29 Correct 45 ms 61436 KB Output is correct
30 Correct 39 ms 61432 KB Output is correct
31 Correct 42 ms 61432 KB Output is correct
32 Correct 39 ms 61432 KB Output is correct
33 Correct 48 ms 61432 KB Output is correct
34 Correct 48 ms 61432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 61432 KB Output is correct
2 Correct 38 ms 61432 KB Output is correct
3 Correct 37 ms 61432 KB Output is correct
4 Correct 37 ms 61432 KB Output is correct
5 Correct 38 ms 61432 KB Output is correct
6 Correct 37 ms 61432 KB Output is correct
7 Correct 38 ms 61304 KB Output is correct
8 Correct 37 ms 61432 KB Output is correct
9 Correct 39 ms 61432 KB Output is correct
10 Correct 39 ms 61432 KB Output is correct
11 Correct 38 ms 61432 KB Output is correct
12 Correct 37 ms 61432 KB Output is correct
13 Correct 38 ms 61432 KB Output is correct
14 Correct 38 ms 61432 KB Output is correct
15 Correct 38 ms 61432 KB Output is correct
16 Correct 38 ms 61432 KB Output is correct
17 Correct 39 ms 61432 KB Output is correct
18 Correct 38 ms 61432 KB Output is correct
19 Correct 38 ms 61440 KB Output is correct
20 Correct 44 ms 61432 KB Output is correct
21 Correct 38 ms 61432 KB Output is correct
22 Correct 39 ms 61432 KB Output is correct
23 Correct 39 ms 61432 KB Output is correct
24 Correct 39 ms 61432 KB Output is correct
25 Correct 38 ms 61432 KB Output is correct
26 Correct 39 ms 61432 KB Output is correct
27 Correct 38 ms 61432 KB Output is correct
28 Correct 39 ms 61432 KB Output is correct
29 Correct 50 ms 61436 KB Output is correct
30 Correct 45 ms 61432 KB Output is correct
31 Correct 48 ms 61432 KB Output is correct
32 Correct 40 ms 61432 KB Output is correct
33 Correct 50 ms 61560 KB Output is correct
34 Correct 54 ms 61432 KB Output is correct
35 Correct 51 ms 61848 KB Output is correct
36 Correct 41 ms 61432 KB Output is correct
37 Correct 61 ms 61768 KB Output is correct
38 Correct 57 ms 62072 KB Output is correct
39 Correct 56 ms 61952 KB Output is correct
40 Correct 56 ms 61944 KB Output is correct
41 Correct 57 ms 62008 KB Output is correct
42 Correct 44 ms 61816 KB Output is correct
43 Correct 48 ms 61868 KB Output is correct
44 Correct 45 ms 61824 KB Output is correct
45 Correct 56 ms 61816 KB Output is correct
46 Correct 61 ms 61944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 61304 KB Output is correct
2 Correct 38 ms 61440 KB Output is correct
3 Correct 37 ms 61312 KB Output is correct
4 Correct 42 ms 61432 KB Output is correct
5 Correct 42 ms 61304 KB Output is correct
6 Correct 37 ms 61432 KB Output is correct
7 Correct 41 ms 61432 KB Output is correct
8 Correct 39 ms 61568 KB Output is correct
9 Correct 42 ms 61304 KB Output is correct
10 Correct 38 ms 61432 KB Output is correct
11 Correct 42 ms 61432 KB Output is correct
12 Correct 42 ms 61432 KB Output is correct
13 Correct 42 ms 61432 KB Output is correct
14 Correct 38 ms 61432 KB Output is correct
15 Correct 38 ms 61432 KB Output is correct
16 Correct 37 ms 61432 KB Output is correct
17 Correct 39 ms 61432 KB Output is correct
18 Correct 38 ms 61432 KB Output is correct
19 Correct 46 ms 61432 KB Output is correct
20 Correct 38 ms 61432 KB Output is correct
21 Correct 43 ms 61432 KB Output is correct
22 Correct 38 ms 61432 KB Output is correct
23 Correct 39 ms 61432 KB Output is correct
24 Correct 39 ms 61436 KB Output is correct
25 Correct 44 ms 61432 KB Output is correct
26 Correct 38 ms 61432 KB Output is correct
27 Correct 38 ms 61432 KB Output is correct
28 Correct 38 ms 61444 KB Output is correct
29 Correct 45 ms 61432 KB Output is correct
30 Correct 41 ms 61436 KB Output is correct
31 Correct 43 ms 61472 KB Output is correct
32 Correct 39 ms 61432 KB Output is correct
33 Correct 48 ms 61552 KB Output is correct
34 Correct 49 ms 61432 KB Output is correct
35 Correct 55 ms 61816 KB Output is correct
36 Correct 43 ms 61432 KB Output is correct
37 Correct 61 ms 61816 KB Output is correct
38 Correct 56 ms 61944 KB Output is correct
39 Correct 56 ms 61896 KB Output is correct
40 Correct 56 ms 61944 KB Output is correct
41 Correct 56 ms 61952 KB Output is correct
42 Correct 50 ms 61816 KB Output is correct
43 Correct 49 ms 61944 KB Output is correct
44 Correct 45 ms 61816 KB Output is correct
45 Correct 64 ms 61816 KB Output is correct
46 Correct 56 ms 62072 KB Output is correct
47 Correct 137 ms 62392 KB Output is correct
48 Correct 47 ms 62072 KB Output is correct
49 Correct 48 ms 61944 KB Output is correct
50 Correct 43 ms 61812 KB Output is correct
51 Correct 91 ms 62776 KB Output is correct
52 Correct 108 ms 62776 KB Output is correct
53 Correct 56 ms 62200 KB Output is correct
54 Correct 38 ms 61432 KB Output is correct
55 Correct 44 ms 61432 KB Output is correct
56 Correct 50 ms 62584 KB Output is correct
57 Correct 134 ms 61432 KB Output is correct
58 Correct 48 ms 61816 KB Output is correct
59 Correct 51 ms 61892 KB Output is correct
60 Correct 57 ms 61824 KB Output is correct
61 Correct 58 ms 61816 KB Output is correct
62 Correct 95 ms 62584 KB Output is correct
63 Correct 88 ms 62708 KB Output is correct
64 Correct 99 ms 62708 KB Output is correct
65 Correct 385 ms 63472 KB Output is correct
66 Correct 917 ms 63472 KB Output is correct
67 Correct 930 ms 63744 KB Output is correct