Submission #28047

# Submission time Handle Problem Language Result Execution time Memory
28047 2017-07-15T03:07:15 Z sampriti Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 261792 KB
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <climits>

using namespace std;

#define LIM 145

int B[30000], P[30000];
set<int> A[30000];
vector<pair<pair<short, unsigned char>, unsigned char> > G[30000][LIM + 1];
int D[30000][LIM + 1];
set<pair<int, pair<short, short> > > Q;

int main() {
  ios::sync_with_stdio(false); cin.tie(0);

  int N, M; cin >> N >> M;

  for(int i = 0; i < M; i++) {
    cin >> B[i] >> P[i];
    A[B[i]].insert(P[i]);
  }

  for(int i = 0; i < N; i++) {
    for(int x: A[i]) {
      if(x < LIM) {
        G[i][LIM].push_back({{i, x}, 0});
      }
    }

    for(int x: A[i]) {
      if(x >= LIM) {
        for(int d = 1; i + d * x < N; d++) {
          if(A[i + d * x].size() == 0) continue;
          G[i][LIM].push_back({{i + d * x, LIM}, d});
        }
        for(int d = 1; i - d * x >= 0; d++) {
          if(A[i - d * x].size() == 0) continue;
          G[i][LIM].push_back({{i - d * x, LIM}, d});
        }
      }
    }

    for(int x = 1; x < LIM; x++) {
      G[i][x].push_back({{i, LIM}, 0});

      if(i + x < N) {
        G[i][x].push_back({{i + x, x}, 1});
      }
      if(i - x >= 0) {
        G[i][x].push_back({{i - x, x}, 1});
      }
    }
  }

  for(int i = 0; i < N; i++) {
    for(int j = 0; j <= LIM; j++) {
      D[i][j] = INT_MAX/2;
    }
  }

  Q.insert({0, {B[0], LIM}}); D[B[0]][LIM] = 0;

  while(!Q.empty()) {
    auto it = *Q.begin(); Q.erase(Q.begin());
    int i = it.second.first, j = it.second.second;

    if(i == B[1] && j == LIM) break;

    for(auto it2: G[i][j]) {
      int i2 = it2.first.first, j2 = it2.first.second, d = it2.second;
      if(D[i][j] + d < D[i2][j2]) {
        if(D[i2][j2] != INT_MAX/2) {
          Q.erase({D[i2][j2], {i2, j2}});
        }
        D[i2][j2] = D[i][j] + d;
        Q.insert({D[i2][j2], {i2, j2}});
      }
    }
  }

  if(D[B[1]][LIM] == INT_MAX/2) {
    cout << -1 << endl;
  }
  else {
    cout << D[B[1]][LIM] << endl;
  }
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 123588 KB Output is correct
2 Correct 26 ms 123588 KB Output is correct
3 Correct 33 ms 123588 KB Output is correct
4 Correct 26 ms 123588 KB Output is correct
5 Correct 29 ms 123588 KB Output is correct
6 Correct 29 ms 123588 KB Output is correct
7 Correct 26 ms 123588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 123588 KB Output is correct
2 Correct 36 ms 123588 KB Output is correct
3 Correct 26 ms 123588 KB Output is correct
4 Correct 23 ms 123588 KB Output is correct
5 Correct 26 ms 123588 KB Output is correct
6 Correct 16 ms 123588 KB Output is correct
7 Correct 16 ms 123588 KB Output is correct
8 Correct 26 ms 123720 KB Output is correct
9 Correct 23 ms 123852 KB Output is correct
10 Correct 33 ms 123984 KB Output is correct
11 Correct 29 ms 124116 KB Output is correct
12 Correct 33 ms 123984 KB Output is correct
13 Correct 33 ms 123984 KB Output is correct
14 Correct 29 ms 124248 KB Output is correct
15 Correct 33 ms 124248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 123588 KB Output is correct
2 Correct 19 ms 123588 KB Output is correct
3 Correct 26 ms 123588 KB Output is correct
4 Correct 43 ms 123588 KB Output is correct
5 Correct 23 ms 123588 KB Output is correct
6 Correct 26 ms 123588 KB Output is correct
7 Correct 33 ms 123588 KB Output is correct
8 Correct 26 ms 123720 KB Output is correct
9 Correct 29 ms 123852 KB Output is correct
10 Correct 36 ms 123984 KB Output is correct
11 Correct 36 ms 124116 KB Output is correct
12 Correct 16 ms 123984 KB Output is correct
13 Correct 33 ms 123984 KB Output is correct
14 Correct 33 ms 124248 KB Output is correct
15 Correct 39 ms 124248 KB Output is correct
16 Correct 33 ms 124512 KB Output is correct
17 Correct 53 ms 127020 KB Output is correct
18 Correct 66 ms 131508 KB Output is correct
19 Correct 66 ms 132564 KB Output is correct
20 Correct 69 ms 132696 KB Output is correct
21 Correct 33 ms 125436 KB Output is correct
22 Correct 53 ms 131640 KB Output is correct
23 Correct 73 ms 130848 KB Output is correct
24 Correct 59 ms 132300 KB Output is correct
25 Correct 63 ms 132696 KB Output is correct
26 Correct 66 ms 132564 KB Output is correct
27 Correct 76 ms 132564 KB Output is correct
28 Correct 76 ms 132696 KB Output is correct
29 Correct 86 ms 132696 KB Output is correct
30 Correct 79 ms 132564 KB Output is correct
31 Correct 79 ms 132564 KB Output is correct
32 Correct 66 ms 132564 KB Output is correct
33 Correct 103 ms 132696 KB Output is correct
34 Correct 83 ms 132696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 123588 KB Output is correct
2 Correct 29 ms 123588 KB Output is correct
3 Correct 33 ms 123588 KB Output is correct
4 Correct 23 ms 123588 KB Output is correct
5 Correct 19 ms 123588 KB Output is correct
6 Correct 23 ms 123588 KB Output is correct
7 Correct 23 ms 123588 KB Output is correct
8 Correct 46 ms 123720 KB Output is correct
9 Correct 23 ms 123852 KB Output is correct
10 Correct 19 ms 123984 KB Output is correct
11 Correct 29 ms 124116 KB Output is correct
12 Correct 33 ms 123984 KB Output is correct
13 Correct 19 ms 123984 KB Output is correct
14 Correct 36 ms 124248 KB Output is correct
15 Correct 36 ms 124248 KB Output is correct
16 Correct 29 ms 124512 KB Output is correct
17 Correct 53 ms 127020 KB Output is correct
18 Correct 63 ms 131508 KB Output is correct
19 Correct 76 ms 132564 KB Output is correct
20 Correct 89 ms 132696 KB Output is correct
21 Correct 33 ms 125436 KB Output is correct
22 Correct 56 ms 131640 KB Output is correct
23 Correct 63 ms 130848 KB Output is correct
24 Correct 76 ms 132300 KB Output is correct
25 Correct 79 ms 132696 KB Output is correct
26 Correct 73 ms 132564 KB Output is correct
27 Correct 69 ms 132564 KB Output is correct
28 Correct 79 ms 132696 KB Output is correct
29 Correct 103 ms 132696 KB Output is correct
30 Correct 73 ms 132564 KB Output is correct
31 Correct 83 ms 132564 KB Output is correct
32 Correct 116 ms 132564 KB Output is correct
33 Correct 119 ms 132696 KB Output is correct
34 Correct 93 ms 132696 KB Output is correct
35 Correct 99 ms 131640 KB Output is correct
36 Correct 46 ms 128736 KB Output is correct
37 Correct 93 ms 133884 KB Output is correct
38 Correct 96 ms 134544 KB Output is correct
39 Correct 103 ms 134412 KB Output is correct
40 Correct 109 ms 134412 KB Output is correct
41 Correct 86 ms 134544 KB Output is correct
42 Correct 69 ms 132564 KB Output is correct
43 Correct 66 ms 132564 KB Output is correct
44 Correct 69 ms 132696 KB Output is correct
45 Correct 186 ms 134544 KB Output is correct
46 Correct 133 ms 134544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 123588 KB Output is correct
2 Correct 19 ms 123588 KB Output is correct
3 Correct 19 ms 123588 KB Output is correct
4 Correct 23 ms 123588 KB Output is correct
5 Correct 13 ms 123588 KB Output is correct
6 Correct 26 ms 123588 KB Output is correct
7 Correct 29 ms 123588 KB Output is correct
8 Correct 36 ms 123720 KB Output is correct
9 Correct 33 ms 123852 KB Output is correct
10 Correct 26 ms 123984 KB Output is correct
11 Correct 26 ms 124116 KB Output is correct
12 Correct 29 ms 123984 KB Output is correct
13 Correct 26 ms 123984 KB Output is correct
14 Correct 29 ms 124248 KB Output is correct
15 Correct 36 ms 124248 KB Output is correct
16 Correct 26 ms 124512 KB Output is correct
17 Correct 56 ms 127020 KB Output is correct
18 Correct 56 ms 131508 KB Output is correct
19 Correct 63 ms 132564 KB Output is correct
20 Correct 89 ms 132696 KB Output is correct
21 Correct 36 ms 125436 KB Output is correct
22 Correct 63 ms 131640 KB Output is correct
23 Correct 63 ms 130848 KB Output is correct
24 Correct 79 ms 132300 KB Output is correct
25 Correct 73 ms 132696 KB Output is correct
26 Correct 69 ms 132564 KB Output is correct
27 Correct 96 ms 132564 KB Output is correct
28 Correct 83 ms 132696 KB Output is correct
29 Correct 96 ms 132696 KB Output is correct
30 Correct 79 ms 132564 KB Output is correct
31 Correct 89 ms 132564 KB Output is correct
32 Correct 73 ms 132564 KB Output is correct
33 Correct 99 ms 132696 KB Output is correct
34 Correct 93 ms 132696 KB Output is correct
35 Correct 69 ms 131640 KB Output is correct
36 Correct 56 ms 128736 KB Output is correct
37 Correct 96 ms 133884 KB Output is correct
38 Correct 83 ms 134544 KB Output is correct
39 Correct 89 ms 134412 KB Output is correct
40 Correct 73 ms 134412 KB Output is correct
41 Correct 79 ms 134544 KB Output is correct
42 Correct 66 ms 132564 KB Output is correct
43 Correct 69 ms 132564 KB Output is correct
44 Correct 73 ms 132696 KB Output is correct
45 Correct 156 ms 134544 KB Output is correct
46 Correct 93 ms 134544 KB Output is correct
47 Correct 353 ms 183252 KB Output is correct
48 Correct 589 ms 229716 KB Output is correct
49 Correct 659 ms 239220 KB Output is correct
50 Correct 703 ms 250176 KB Output is correct
51 Correct 769 ms 261264 KB Output is correct
52 Correct 756 ms 261264 KB Output is correct
53 Correct 706 ms 260076 KB Output is correct
54 Correct 743 ms 258492 KB Output is correct
55 Correct 699 ms 258492 KB Output is correct
56 Correct 783 ms 260868 KB Output is correct
57 Correct 643 ms 258756 KB Output is correct
58 Correct 819 ms 258492 KB Output is correct
59 Correct 803 ms 258624 KB Output is correct
60 Correct 736 ms 258624 KB Output is correct
61 Correct 709 ms 258756 KB Output is correct
62 Correct 823 ms 261792 KB Output is correct
63 Correct 716 ms 260076 KB Output is correct
64 Correct 799 ms 260076 KB Output is correct
65 Execution timed out 1000 ms 260208 KB Execution timed out
66 Halted 0 ms 0 KB -