답안 #45670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45670 2018-04-16T01:52:51 Z Trans Jakarta Skyscrapers (APIO15_skyscraper) C++14
22 / 100
17 ms 3800 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 d[cur.se];
    // cout << "here " << cur.se << endl;
    heap.pop();
    for (auto it = st[1][cur.se].begin(); it != st[1][cur.se].end(); it++) {
      int jump = *it;
      int pos = cur.se % jump;
      for (int i = pos; i < n; i += jump) {
        if (d[i] > cur.fi + abs(cur.se - i) / jump) {
          d[i] = cur.fi + abs(cur.se - i) / jump;
          heap.push(mp(-d[i], i));
        }
      }
    }

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

        st[0][pre].insert(jump);
      }
      else {
        if (pre >= 0 && st[0][pre].find(jump) == st[0][pre].end()) {
          st[0][pre].insert(jump);
          heap.push(mp(-(cur.fi + 1), pre));
        }
      }
    }
  }

  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;
    if (y <= k) st[0][x].insert(y);
    else st[1][x].insert(y);
  }

  cout << dij(); 

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3192 KB Output is correct
2 Correct 4 ms 3304 KB Output is correct
3 Correct 4 ms 3304 KB Output is correct
4 Correct 4 ms 3304 KB Output is correct
5 Correct 4 ms 3304 KB Output is correct
6 Correct 4 ms 3468 KB Output is correct
7 Correct 4 ms 3468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3468 KB Output is correct
2 Correct 4 ms 3468 KB Output is correct
3 Correct 4 ms 3468 KB Output is correct
4 Correct 4 ms 3468 KB Output is correct
5 Correct 4 ms 3468 KB Output is correct
6 Correct 4 ms 3468 KB Output is correct
7 Correct 4 ms 3468 KB Output is correct
8 Correct 4 ms 3468 KB Output is correct
9 Correct 4 ms 3540 KB Output is correct
10 Correct 4 ms 3540 KB Output is correct
11 Correct 5 ms 3540 KB Output is correct
12 Correct 5 ms 3540 KB Output is correct
13 Correct 5 ms 3540 KB Output is correct
14 Correct 16 ms 3684 KB Output is correct
15 Correct 6 ms 3684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3684 KB Output is correct
2 Correct 4 ms 3684 KB Output is correct
3 Correct 4 ms 3684 KB Output is correct
4 Correct 4 ms 3684 KB Output is correct
5 Correct 4 ms 3684 KB Output is correct
6 Correct 4 ms 3684 KB Output is correct
7 Correct 4 ms 3684 KB Output is correct
8 Correct 4 ms 3684 KB Output is correct
9 Correct 4 ms 3684 KB Output is correct
10 Correct 4 ms 3684 KB Output is correct
11 Correct 5 ms 3684 KB Output is correct
12 Correct 5 ms 3684 KB Output is correct
13 Correct 5 ms 3684 KB Output is correct
14 Correct 17 ms 3800 KB Output is correct
15 Correct 5 ms 3800 KB Output is correct
16 Correct 5 ms 3800 KB Output is correct
17 Correct 6 ms 3800 KB Output is correct
18 Correct 5 ms 3800 KB Output is correct
19 Correct 4 ms 3800 KB Output is correct
20 Correct 5 ms 3800 KB Output is correct
21 Correct 4 ms 3800 KB Output is correct
22 Correct 4 ms 3800 KB Output is correct
23 Incorrect 6 ms 3800 KB Output isn't correct
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3800 KB Output is correct
2 Correct 4 ms 3800 KB Output is correct
3 Correct 4 ms 3800 KB Output is correct
4 Correct 4 ms 3800 KB Output is correct
5 Correct 4 ms 3800 KB Output is correct
6 Correct 4 ms 3800 KB Output is correct
7 Correct 4 ms 3800 KB Output is correct
8 Correct 4 ms 3800 KB Output is correct
9 Correct 4 ms 3800 KB Output is correct
10 Correct 4 ms 3800 KB Output is correct
11 Correct 5 ms 3800 KB Output is correct
12 Correct 5 ms 3800 KB Output is correct
13 Correct 4 ms 3800 KB Output is correct
14 Correct 16 ms 3800 KB Output is correct
15 Correct 6 ms 3800 KB Output is correct
16 Correct 4 ms 3800 KB Output is correct
17 Correct 6 ms 3800 KB Output is correct
18 Correct 4 ms 3800 KB Output is correct
19 Correct 4 ms 3800 KB Output is correct
20 Correct 5 ms 3800 KB Output is correct
21 Correct 4 ms 3800 KB Output is correct
22 Correct 4 ms 3800 KB Output is correct
23 Incorrect 6 ms 3800 KB Output isn't correct
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3800 KB Output is correct
2 Correct 4 ms 3800 KB Output is correct
3 Correct 4 ms 3800 KB Output is correct
4 Correct 4 ms 3800 KB Output is correct
5 Correct 4 ms 3800 KB Output is correct
6 Correct 4 ms 3800 KB Output is correct
7 Correct 4 ms 3800 KB Output is correct
8 Correct 4 ms 3800 KB Output is correct
9 Correct 5 ms 3800 KB Output is correct
10 Correct 4 ms 3800 KB Output is correct
11 Correct 5 ms 3800 KB Output is correct
12 Correct 4 ms 3800 KB Output is correct
13 Correct 5 ms 3800 KB Output is correct
14 Correct 16 ms 3800 KB Output is correct
15 Correct 6 ms 3800 KB Output is correct
16 Correct 5 ms 3800 KB Output is correct
17 Correct 6 ms 3800 KB Output is correct
18 Correct 5 ms 3800 KB Output is correct
19 Correct 4 ms 3800 KB Output is correct
20 Correct 5 ms 3800 KB Output is correct
21 Correct 4 ms 3800 KB Output is correct
22 Correct 5 ms 3800 KB Output is correct
23 Incorrect 6 ms 3800 KB Output isn't correct
24 Halted 0 ms 0 KB -