Submission #28037

# Submission time Handle Problem Language Result Execution time Memory
28037 2017-07-15T00:40:24 Z sampriti Jakarta Skyscrapers (APIO15_skyscraper) C++14
22 / 100
113 ms 128188 KB
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <climits>

using namespace std;

#define LIM 150

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

int main() {
  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++) {
          G[i][LIM].push_back({{i + d * x, LIM}, d});
        }
        for(int d = 1; i - d * x >= 0; d++) {
          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] = SHRT_MAX/2;
    }
  }

  set<pair<int, pair<int, int> > > Q;
  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;

    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] != SHRT_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] == SHRT_MAX/2) {
    cout << -1 << endl;
  }
  else {
    cout << D[B[1]][LIM] << endl;
  }
}
# Verdict Execution time Memory Grader output
1 Correct 36 ms 118684 KB Output is correct
2 Correct 26 ms 118684 KB Output is correct
3 Correct 23 ms 118684 KB Output is correct
4 Correct 26 ms 118684 KB Output is correct
5 Correct 19 ms 118684 KB Output is correct
6 Correct 29 ms 118684 KB Output is correct
7 Correct 23 ms 118684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 118684 KB Output is correct
2 Correct 29 ms 118684 KB Output is correct
3 Correct 26 ms 118684 KB Output is correct
4 Correct 26 ms 118684 KB Output is correct
5 Correct 16 ms 118684 KB Output is correct
6 Correct 39 ms 118684 KB Output is correct
7 Correct 43 ms 118684 KB Output is correct
8 Correct 26 ms 118816 KB Output is correct
9 Correct 26 ms 118948 KB Output is correct
10 Correct 29 ms 119212 KB Output is correct
11 Correct 33 ms 119344 KB Output is correct
12 Correct 33 ms 119212 KB Output is correct
13 Correct 29 ms 119212 KB Output is correct
14 Correct 36 ms 119344 KB Output is correct
15 Correct 29 ms 119344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 118684 KB Output is correct
2 Correct 29 ms 118684 KB Output is correct
3 Correct 29 ms 118684 KB Output is correct
4 Correct 33 ms 118684 KB Output is correct
5 Correct 43 ms 118684 KB Output is correct
6 Correct 23 ms 118684 KB Output is correct
7 Correct 19 ms 118684 KB Output is correct
8 Correct 26 ms 118816 KB Output is correct
9 Correct 19 ms 118948 KB Output is correct
10 Correct 26 ms 119212 KB Output is correct
11 Correct 23 ms 119344 KB Output is correct
12 Correct 36 ms 119212 KB Output is correct
13 Correct 36 ms 119212 KB Output is correct
14 Correct 46 ms 119344 KB Output is correct
15 Correct 23 ms 119344 KB Output is correct
16 Correct 29 ms 119740 KB Output is correct
17 Correct 63 ms 122380 KB Output is correct
18 Correct 66 ms 126868 KB Output is correct
19 Correct 66 ms 128056 KB Output is correct
20 Correct 99 ms 128188 KB Output is correct
21 Correct 33 ms 120532 KB Output is correct
22 Correct 69 ms 127000 KB Output is correct
23 Correct 69 ms 126208 KB Output is correct
24 Correct 89 ms 127660 KB Output is correct
25 Correct 83 ms 128188 KB Output is correct
26 Correct 113 ms 128056 KB Output is correct
27 Correct 76 ms 128056 KB Output is correct
28 Incorrect 86 ms 128188 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 118684 KB Output is correct
2 Correct 29 ms 118684 KB Output is correct
3 Correct 26 ms 118684 KB Output is correct
4 Correct 36 ms 118684 KB Output is correct
5 Correct 26 ms 118684 KB Output is correct
6 Correct 26 ms 118684 KB Output is correct
7 Correct 26 ms 118684 KB Output is correct
8 Correct 23 ms 118816 KB Output is correct
9 Correct 36 ms 118948 KB Output is correct
10 Correct 29 ms 119212 KB Output is correct
11 Correct 29 ms 119344 KB Output is correct
12 Correct 43 ms 119212 KB Output is correct
13 Correct 26 ms 119212 KB Output is correct
14 Correct 26 ms 119344 KB Output is correct
15 Correct 26 ms 119344 KB Output is correct
16 Correct 29 ms 119740 KB Output is correct
17 Correct 63 ms 122380 KB Output is correct
18 Correct 66 ms 126868 KB Output is correct
19 Correct 66 ms 128056 KB Output is correct
20 Correct 86 ms 128188 KB Output is correct
21 Correct 33 ms 120532 KB Output is correct
22 Correct 63 ms 127000 KB Output is correct
23 Correct 76 ms 126208 KB Output is correct
24 Correct 83 ms 127660 KB Output is correct
25 Correct 76 ms 128188 KB Output is correct
26 Correct 79 ms 128056 KB Output is correct
27 Correct 79 ms 128056 KB Output is correct
28 Incorrect 83 ms 128188 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 118684 KB Output is correct
2 Correct 26 ms 118684 KB Output is correct
3 Correct 26 ms 118684 KB Output is correct
4 Correct 33 ms 118684 KB Output is correct
5 Correct 26 ms 118684 KB Output is correct
6 Correct 29 ms 118684 KB Output is correct
7 Correct 26 ms 118684 KB Output is correct
8 Correct 19 ms 118816 KB Output is correct
9 Correct 19 ms 118948 KB Output is correct
10 Correct 36 ms 119212 KB Output is correct
11 Correct 33 ms 119344 KB Output is correct
12 Correct 16 ms 119212 KB Output is correct
13 Correct 29 ms 119212 KB Output is correct
14 Correct 26 ms 119344 KB Output is correct
15 Correct 29 ms 119344 KB Output is correct
16 Correct 19 ms 119740 KB Output is correct
17 Correct 66 ms 122380 KB Output is correct
18 Correct 59 ms 126868 KB Output is correct
19 Correct 76 ms 128056 KB Output is correct
20 Correct 79 ms 128188 KB Output is correct
21 Correct 29 ms 120532 KB Output is correct
22 Correct 73 ms 127000 KB Output is correct
23 Correct 63 ms 126208 KB Output is correct
24 Correct 86 ms 127660 KB Output is correct
25 Correct 79 ms 128188 KB Output is correct
26 Correct 89 ms 128056 KB Output is correct
27 Correct 83 ms 128056 KB Output is correct
28 Incorrect 73 ms 128188 KB Output isn't correct
29 Halted 0 ms 0 KB -