Submission #45687

# Submission time Handle Problem Language Result Execution time Memory
45687 2018-04-16T03:08:07 Z Trans Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
141 ms 7156 KB
//https://oj.uz/problem/view/APIO15_skyscraper

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pii;

const int k = 200;
const int oo = 1e9 + 5;
const int maxn = 3e4 + 5;

int n, m, d[maxn], vs[maxn], ss, ee;
set<int> st[2][maxn];

int dij() {
  priority_queue<pii> heap;
  rep(i, 0, n) d[i] = oo;
  d[ss] = 0;
  heap.push(mp(0, ss));

  while (!heap.empty()) {
    pii cur = heap.top();
    cur.fi *= -1;
    if (cur.se == ee) return cur.fi;
    // cout << "here " << cur.se << endl;
    heap.pop();
    // cout << cur.se << endl;
    if (vs[cur.se]) continue;
    vs[cur.se] = 1;

    for (auto it = st[0][cur.se].begin(); it != st[0][cur.se].end(); it++) {
      int jump = *it;
      int now = cur.se;
      assert(jump != 0);
      int cnt = 0;
      while (cur.se + jump < n) {
        int nxt = cur.se + jump;
        cnt++;
        if (d[nxt] > cur.fi + cnt) {
          d[nxt] = cur.fi + cnt;
          heap.push(mp(-d[nxt], nxt));
        }
        if (st[0][nxt].find(jump) != st[0][nxt].end()) break;
        cur.se = nxt;
      }
      cur.se = now;
      cnt = 0;
      while (cur.se - jump >= 0) {
        int pre = cur.se - jump;
        cnt++;
        if (d[pre] > cur.fi + cnt) {
          d[pre] = cur.fi + cnt;
          heap.push(mp(-d[pre], pre));
        }
        if (st[0][pre].find(jump) != st[0][pre].end()) break;
        cur.se = pre;
      }
      cur.se = now;
    }
  }

  return -1;
}

int main() {
  // freopen("inp.txt", "r", stdin);

  cin >> n >> m;

  rep(i, 0, m) {
    int x, y;
    cin >> x >> y;
    if (i == 0) ss = x;
    if (i == 1) ee = x;
    st[0][x].insert(y);
    // else st[1][x].insert(y);
  }

  cout << dij(); 

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3064 KB Output is correct
2 Correct 5 ms 3172 KB Output is correct
3 Correct 5 ms 3208 KB Output is correct
4 Correct 5 ms 3208 KB Output is correct
5 Correct 5 ms 3224 KB Output is correct
6 Correct 5 ms 3276 KB Output is correct
7 Correct 5 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3404 KB Output is correct
2 Correct 4 ms 3404 KB Output is correct
3 Correct 4 ms 3404 KB Output is correct
4 Correct 4 ms 3404 KB Output is correct
5 Correct 5 ms 3404 KB Output is correct
6 Correct 5 ms 3404 KB Output is correct
7 Correct 5 ms 3404 KB Output is correct
8 Correct 4 ms 3404 KB Output is correct
9 Correct 5 ms 3404 KB Output is correct
10 Correct 5 ms 3404 KB Output is correct
11 Correct 7 ms 3404 KB Output is correct
12 Correct 5 ms 3404 KB Output is correct
13 Correct 7 ms 3404 KB Output is correct
14 Correct 7 ms 3404 KB Output is correct
15 Correct 7 ms 3488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3488 KB Output is correct
2 Correct 5 ms 3488 KB Output is correct
3 Correct 5 ms 3488 KB Output is correct
4 Correct 4 ms 3488 KB Output is correct
5 Correct 4 ms 3488 KB Output is correct
6 Correct 4 ms 3488 KB Output is correct
7 Correct 4 ms 3488 KB Output is correct
8 Correct 4 ms 3488 KB Output is correct
9 Correct 4 ms 3488 KB Output is correct
10 Correct 5 ms 3488 KB Output is correct
11 Correct 5 ms 3564 KB Output is correct
12 Correct 5 ms 3564 KB Output is correct
13 Correct 5 ms 3564 KB Output is correct
14 Correct 5 ms 3564 KB Output is correct
15 Correct 5 ms 3564 KB Output is correct
16 Correct 5 ms 3564 KB Output is correct
17 Correct 6 ms 3564 KB Output is correct
18 Correct 5 ms 3564 KB Output is correct
19 Correct 5 ms 3564 KB Output is correct
20 Correct 6 ms 3564 KB Output is correct
21 Correct 5 ms 3564 KB Output is correct
22 Correct 4 ms 3564 KB Output is correct
23 Correct 5 ms 3564 KB Output is correct
24 Correct 8 ms 3580 KB Output is correct
25 Correct 6 ms 3580 KB Output is correct
26 Correct 7 ms 3580 KB Output is correct
27 Correct 5 ms 3580 KB Output is correct
28 Correct 6 ms 3580 KB Output is correct
29 Correct 6 ms 3580 KB Output is correct
30 Correct 5 ms 3580 KB Output is correct
31 Correct 5 ms 3580 KB Output is correct
32 Correct 5 ms 3580 KB Output is correct
33 Correct 10 ms 3708 KB Output is correct
34 Correct 7 ms 3708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3708 KB Output is correct
2 Correct 4 ms 3708 KB Output is correct
3 Correct 5 ms 3708 KB Output is correct
4 Correct 4 ms 3708 KB Output is correct
5 Correct 4 ms 3708 KB Output is correct
6 Correct 4 ms 3708 KB Output is correct
7 Correct 5 ms 3708 KB Output is correct
8 Correct 4 ms 3708 KB Output is correct
9 Correct 5 ms 3708 KB Output is correct
10 Correct 4 ms 3708 KB Output is correct
11 Correct 5 ms 3708 KB Output is correct
12 Correct 6 ms 3708 KB Output is correct
13 Correct 5 ms 3708 KB Output is correct
14 Correct 6 ms 3708 KB Output is correct
15 Correct 5 ms 3708 KB Output is correct
16 Correct 6 ms 3708 KB Output is correct
17 Correct 5 ms 3708 KB Output is correct
18 Correct 5 ms 3708 KB Output is correct
19 Correct 4 ms 3708 KB Output is correct
20 Correct 5 ms 3708 KB Output is correct
21 Correct 5 ms 3708 KB Output is correct
22 Correct 5 ms 3708 KB Output is correct
23 Correct 6 ms 3708 KB Output is correct
24 Correct 6 ms 3708 KB Output is correct
25 Correct 7 ms 3708 KB Output is correct
26 Correct 5 ms 3708 KB Output is correct
27 Correct 6 ms 3708 KB Output is correct
28 Correct 7 ms 3708 KB Output is correct
29 Correct 6 ms 3708 KB Output is correct
30 Correct 5 ms 3708 KB Output is correct
31 Correct 6 ms 3708 KB Output is correct
32 Correct 5 ms 3708 KB Output is correct
33 Correct 9 ms 3708 KB Output is correct
34 Correct 7 ms 3708 KB Output is correct
35 Correct 29 ms 4604 KB Output is correct
36 Correct 9 ms 4604 KB Output is correct
37 Correct 24 ms 4604 KB Output is correct
38 Correct 37 ms 4860 KB Output is correct
39 Correct 29 ms 4860 KB Output is correct
40 Correct 32 ms 4860 KB Output is correct
41 Correct 36 ms 4860 KB Output is correct
42 Correct 34 ms 4860 KB Output is correct
43 Correct 30 ms 4860 KB Output is correct
44 Correct 34 ms 4860 KB Output is correct
45 Correct 57 ms 4988 KB Output is correct
46 Correct 41 ms 4988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4988 KB Output is correct
2 Correct 4 ms 4988 KB Output is correct
3 Correct 5 ms 4988 KB Output is correct
4 Correct 4 ms 4988 KB Output is correct
5 Correct 4 ms 4988 KB Output is correct
6 Correct 5 ms 4988 KB Output is correct
7 Correct 4 ms 4988 KB Output is correct
8 Correct 4 ms 4988 KB Output is correct
9 Correct 5 ms 4988 KB Output is correct
10 Correct 4 ms 4988 KB Output is correct
11 Correct 5 ms 4988 KB Output is correct
12 Correct 6 ms 4988 KB Output is correct
13 Correct 6 ms 4988 KB Output is correct
14 Correct 6 ms 4988 KB Output is correct
15 Correct 5 ms 4988 KB Output is correct
16 Correct 4 ms 4988 KB Output is correct
17 Correct 6 ms 4988 KB Output is correct
18 Correct 5 ms 4988 KB Output is correct
19 Correct 6 ms 4988 KB Output is correct
20 Correct 6 ms 4988 KB Output is correct
21 Correct 5 ms 4988 KB Output is correct
22 Correct 5 ms 4988 KB Output is correct
23 Correct 7 ms 4988 KB Output is correct
24 Correct 7 ms 4988 KB Output is correct
25 Correct 6 ms 4988 KB Output is correct
26 Correct 5 ms 4988 KB Output is correct
27 Correct 6 ms 4988 KB Output is correct
28 Correct 5 ms 4988 KB Output is correct
29 Correct 6 ms 4988 KB Output is correct
30 Correct 5 ms 4988 KB Output is correct
31 Correct 5 ms 4988 KB Output is correct
32 Correct 6 ms 4988 KB Output is correct
33 Correct 8 ms 4988 KB Output is correct
34 Correct 9 ms 4988 KB Output is correct
35 Correct 30 ms 4988 KB Output is correct
36 Correct 9 ms 4988 KB Output is correct
37 Correct 30 ms 4988 KB Output is correct
38 Correct 55 ms 4988 KB Output is correct
39 Correct 29 ms 4988 KB Output is correct
40 Correct 30 ms 4988 KB Output is correct
41 Correct 39 ms 4988 KB Output is correct
42 Correct 20 ms 4988 KB Output is correct
43 Correct 34 ms 4988 KB Output is correct
44 Correct 26 ms 4988 KB Output is correct
45 Correct 40 ms 5004 KB Output is correct
46 Correct 36 ms 5004 KB Output is correct
47 Correct 35 ms 5004 KB Output is correct
48 Correct 24 ms 5004 KB Output is correct
49 Correct 27 ms 5004 KB Output is correct
50 Correct 25 ms 5004 KB Output is correct
51 Correct 43 ms 5624 KB Output is correct
52 Correct 53 ms 5628 KB Output is correct
53 Correct 36 ms 5628 KB Output is correct
54 Correct 6 ms 5628 KB Output is correct
55 Correct 9 ms 5628 KB Output is correct
56 Correct 47 ms 5628 KB Output is correct
57 Correct 10 ms 5628 KB Output is correct
58 Correct 30 ms 5628 KB Output is correct
59 Correct 41 ms 5628 KB Output is correct
60 Correct 30 ms 5628 KB Output is correct
61 Correct 26 ms 5628 KB Output is correct
62 Correct 36 ms 5628 KB Output is correct
63 Correct 71 ms 6140 KB Output is correct
64 Correct 62 ms 6140 KB Output is correct
65 Correct 73 ms 6140 KB Output is correct
66 Correct 141 ms 7156 KB Output is correct
67 Correct 85 ms 7156 KB Output is correct