Submission #28028

# Submission time Handle Problem Language Result Execution time Memory
28028 2017-07-14T21:33:49 Z sampriti Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
323 ms 238000 KB
#include <iostream>
#include <algorithm>
#include <deque>

using namespace std;

int B[30000], P[30000];
vector<int> A[30000];
int vis[2000][30001];

int main() {
  int N, M; cin >> N >> M;

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

  int ans = -1;
  deque<pair<int, int> > Q;
  Q.push_back({B[0], M});
  vis[B[0]][M] = 1;

  while(!Q.empty()) {
    auto it = Q.front(); Q.pop_front();
    int i = it.first, j = it.second;

    if(i == B[1]) {
      ans = vis[i][j];
      break;
    }

    if(j == M) {
      for(int k: A[i]) {
        if(!vis[i][k]) {
          vis[i][k] = vis[i][j];
          Q.push_front({i, k});
        }
      }
    }
    else {
      if(i - P[j] >= 0 && !vis[i - P[j]][j]) {
        vis[i - P[j]][j] = vis[i][j] + 1;
        Q.push_back({i - P[j], j});
      }

      if(i + P[j] < N && !vis[i + P[j]][j]) {
        vis[i + P[j]][j] = vis[i][j] + 1;
        Q.push_back({i + P[j], j});
      }

      if(!vis[i][M]) {
        vis[i][M] = vis[i][j];
        Q.push_front({i, M});
      }
    }
  }

  if(ans != -1) ans -= 1;
  cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 237340 KB Output is correct
2 Correct 0 ms 237340 KB Output is correct
3 Correct 0 ms 237340 KB Output is correct
4 Correct 0 ms 237340 KB Output is correct
5 Correct 0 ms 237340 KB Output is correct
6 Correct 0 ms 237340 KB Output is correct
7 Correct 0 ms 237340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 237340 KB Output is correct
2 Correct 0 ms 237340 KB Output is correct
3 Correct 0 ms 237340 KB Output is correct
4 Correct 0 ms 237340 KB Output is correct
5 Correct 0 ms 237340 KB Output is correct
6 Correct 0 ms 237340 KB Output is correct
7 Correct 0 ms 237340 KB Output is correct
8 Correct 0 ms 237340 KB Output is correct
9 Correct 0 ms 237340 KB Output is correct
10 Correct 0 ms 237340 KB Output is correct
11 Correct 0 ms 237340 KB Output is correct
12 Correct 0 ms 237340 KB Output is correct
13 Correct 0 ms 237340 KB Output is correct
14 Correct 0 ms 237340 KB Output is correct
15 Correct 0 ms 237340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 237340 KB Output is correct
2 Correct 0 ms 237340 KB Output is correct
3 Correct 0 ms 237340 KB Output is correct
4 Correct 0 ms 237340 KB Output is correct
5 Correct 0 ms 237340 KB Output is correct
6 Correct 0 ms 237340 KB Output is correct
7 Correct 0 ms 237340 KB Output is correct
8 Correct 0 ms 237340 KB Output is correct
9 Correct 0 ms 237340 KB Output is correct
10 Correct 0 ms 237340 KB Output is correct
11 Correct 0 ms 237340 KB Output is correct
12 Correct 0 ms 237340 KB Output is correct
13 Correct 3 ms 237340 KB Output is correct
14 Correct 0 ms 237340 KB Output is correct
15 Correct 3 ms 237340 KB Output is correct
16 Correct 0 ms 237340 KB Output is correct
17 Correct 0 ms 237340 KB Output is correct
18 Correct 0 ms 237340 KB Output is correct
19 Correct 0 ms 237340 KB Output is correct
20 Correct 153 ms 237472 KB Output is correct
21 Correct 0 ms 237340 KB Output is correct
22 Correct 0 ms 237340 KB Output is correct
23 Correct 0 ms 237340 KB Output is correct
24 Correct 3 ms 237340 KB Output is correct
25 Correct 3 ms 237340 KB Output is correct
26 Correct 3 ms 237340 KB Output is correct
27 Correct 3 ms 237340 KB Output is correct
28 Correct 13 ms 237472 KB Output is correct
29 Correct 9 ms 237340 KB Output is correct
30 Correct 6 ms 237340 KB Output is correct
31 Correct 3 ms 237340 KB Output is correct
32 Correct 6 ms 237340 KB Output is correct
33 Correct 9 ms 237340 KB Output is correct
34 Correct 9 ms 237340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 237340 KB Output is correct
2 Correct 0 ms 237340 KB Output is correct
3 Correct 0 ms 237340 KB Output is correct
4 Correct 0 ms 237340 KB Output is correct
5 Correct 0 ms 237340 KB Output is correct
6 Correct 0 ms 237340 KB Output is correct
7 Correct 0 ms 237340 KB Output is correct
8 Correct 0 ms 237340 KB Output is correct
9 Correct 0 ms 237340 KB Output is correct
10 Correct 0 ms 237340 KB Output is correct
11 Correct 0 ms 237340 KB Output is correct
12 Correct 0 ms 237340 KB Output is correct
13 Correct 3 ms 237340 KB Output is correct
14 Correct 0 ms 237340 KB Output is correct
15 Correct 0 ms 237340 KB Output is correct
16 Correct 0 ms 237340 KB Output is correct
17 Correct 3 ms 237340 KB Output is correct
18 Correct 0 ms 237340 KB Output is correct
19 Correct 0 ms 237340 KB Output is correct
20 Correct 179 ms 237472 KB Output is correct
21 Correct 0 ms 237340 KB Output is correct
22 Correct 0 ms 237340 KB Output is correct
23 Correct 0 ms 237340 KB Output is correct
24 Correct 6 ms 237340 KB Output is correct
25 Correct 3 ms 237340 KB Output is correct
26 Correct 0 ms 237340 KB Output is correct
27 Correct 6 ms 237340 KB Output is correct
28 Correct 9 ms 237472 KB Output is correct
29 Correct 9 ms 237340 KB Output is correct
30 Correct 3 ms 237340 KB Output is correct
31 Correct 13 ms 237340 KB Output is correct
32 Correct 6 ms 237340 KB Output is correct
33 Correct 16 ms 237340 KB Output is correct
34 Correct 9 ms 237340 KB Output is correct
35 Correct 29 ms 237736 KB Output is correct
36 Correct 3 ms 237472 KB Output is correct
37 Correct 19 ms 237736 KB Output is correct
38 Correct 23 ms 237736 KB Output is correct
39 Correct 19 ms 237604 KB Output is correct
40 Correct 23 ms 237604 KB Output is correct
41 Correct 43 ms 237736 KB Output is correct
42 Correct 13 ms 237616 KB Output is correct
43 Correct 16 ms 237616 KB Output is correct
44 Correct 283 ms 238000 KB Output is correct
45 Correct 139 ms 237736 KB Output is correct
46 Correct 106 ms 237736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 237340 KB Output is correct
2 Correct 0 ms 237340 KB Output is correct
3 Correct 0 ms 237340 KB Output is correct
4 Correct 0 ms 237340 KB Output is correct
5 Correct 0 ms 237340 KB Output is correct
6 Correct 0 ms 237340 KB Output is correct
7 Correct 0 ms 237340 KB Output is correct
8 Correct 0 ms 237340 KB Output is correct
9 Correct 0 ms 237340 KB Output is correct
10 Correct 0 ms 237340 KB Output is correct
11 Correct 3 ms 237340 KB Output is correct
12 Correct 0 ms 237340 KB Output is correct
13 Correct 3 ms 237340 KB Output is correct
14 Correct 3 ms 237340 KB Output is correct
15 Correct 3 ms 237340 KB Output is correct
16 Correct 0 ms 237340 KB Output is correct
17 Correct 0 ms 237340 KB Output is correct
18 Correct 0 ms 237340 KB Output is correct
19 Correct 0 ms 237340 KB Output is correct
20 Correct 169 ms 237472 KB Output is correct
21 Correct 0 ms 237340 KB Output is correct
22 Correct 0 ms 237340 KB Output is correct
23 Correct 0 ms 237340 KB Output is correct
24 Correct 9 ms 237340 KB Output is correct
25 Correct 0 ms 237340 KB Output is correct
26 Correct 6 ms 237340 KB Output is correct
27 Correct 9 ms 237340 KB Output is correct
28 Correct 6 ms 237472 KB Output is correct
29 Correct 3 ms 237340 KB Output is correct
30 Correct 3 ms 237340 KB Output is correct
31 Correct 0 ms 237340 KB Output is correct
32 Correct 0 ms 237340 KB Output is correct
33 Correct 16 ms 237340 KB Output is correct
34 Correct 0 ms 237340 KB Output is correct
35 Correct 43 ms 237736 KB Output is correct
36 Correct 3 ms 237472 KB Output is correct
37 Correct 26 ms 237736 KB Output is correct
38 Correct 29 ms 237736 KB Output is correct
39 Correct 19 ms 237604 KB Output is correct
40 Correct 23 ms 237604 KB Output is correct
41 Correct 36 ms 237736 KB Output is correct
42 Correct 19 ms 237616 KB Output is correct
43 Correct 23 ms 237616 KB Output is correct
44 Correct 323 ms 238000 KB Output is correct
45 Correct 126 ms 237736 KB Output is correct
46 Correct 99 ms 237736 KB Output is correct
47 Runtime error 13 ms 237736 KB Execution killed with signal 11 (could be triggered by violating memory limits)
48 Halted 0 ms 0 KB -