Submission #457936

# Submission time Handle Problem Language Result Execution time Memory
457936 2021-08-07T15:06:36 Z elgamalsalman Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 2696 KB
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ww first
#define vv second

typedef long long ll;
typedef pair<ll, ll> llll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

int N, M, b[30'050], p[30'050];
ll sssp[30'050];
vvi dogesAt;
bitset<30'050> visited;

void bfs() {
  memset(sssp, -1, sizeof sssp);
  queue<iii> q;
  for (int doge : dogesAt[b[0]]) {
    sssp[doge] = 0;
    visited[doge] = 1;
    if (doge == 1) return;
    q.push({b[0], {p[doge], 0}});
    q.push({b[0], {-p[doge], 0}});
  }
  while (!q.empty()) {
    iii u = q.front(); q.pop();
    //cerr << "// {" << u.fi << ", {" << u.se.fi << ", " << u.se.se << "}}\n";
    int newPos = u.fi + u.se.fi;
    if (newPos >= 0 && newPos < N) {
      q.push({newPos, {u.se.fi, u.se.se + 1}});
      for (int doge : dogesAt[newPos]) if (!visited[doge]) {
	sssp[doge] = u.se.se + 1;
	visited[doge] = 1;
	if (doge == 1) return;
	q.push({newPos, {p[doge], u.se.se + 1}});
	q.push({newPos, {-p[doge], u.se.se + 1}});
      }
    }
  }
}

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

  cin >> N >> M;
  dogesAt.assign(N + 20, vi());
  for (int i = 0; i < M; i++) {
    cin >> b[i] >> p[i];
    dogesAt[b[i]].push_back(i);
  }
  
  bfs();

  //cerr << "// sssp :";
  //for (int i = 0; i < M; i++) cerr << ' ' << sssp[i];
  //cerr << '\n';

  cout << sssp[1] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 43 ms 708 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Correct 1 ms 588 KB Output is correct
23 Correct 1 ms 588 KB Output is correct
24 Correct 1 ms 588 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 1 ms 588 KB Output is correct
27 Correct 1 ms 588 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 1 ms 588 KB Output is correct
30 Correct 1 ms 588 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 1 ms 588 KB Output is correct
33 Correct 2 ms 588 KB Output is correct
34 Correct 2 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 556 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 2 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 43 ms 720 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Correct 1 ms 588 KB Output is correct
23 Correct 1 ms 588 KB Output is correct
24 Correct 1 ms 588 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 1 ms 588 KB Output is correct
27 Correct 1 ms 588 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 1 ms 588 KB Output is correct
30 Correct 1 ms 588 KB Output is correct
31 Correct 1 ms 588 KB Output is correct
32 Correct 1 ms 588 KB Output is correct
33 Correct 2 ms 588 KB Output is correct
34 Correct 2 ms 588 KB Output is correct
35 Correct 8 ms 1484 KB Output is correct
36 Correct 2 ms 628 KB Output is correct
37 Correct 6 ms 1100 KB Output is correct
38 Correct 9 ms 1636 KB Output is correct
39 Correct 7 ms 1032 KB Output is correct
40 Correct 8 ms 1100 KB Output is correct
41 Correct 8 ms 1084 KB Output is correct
42 Correct 6 ms 980 KB Output is correct
43 Correct 6 ms 980 KB Output is correct
44 Correct 115 ms 1732 KB Output is correct
45 Correct 19 ms 1740 KB Output is correct
46 Correct 13 ms 1772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 42 ms 712 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Correct 1 ms 588 KB Output is correct
23 Correct 1 ms 588 KB Output is correct
24 Correct 1 ms 588 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 1 ms 588 KB Output is correct
27 Correct 1 ms 588 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 1 ms 644 KB Output is correct
30 Correct 1 ms 588 KB Output is correct
31 Correct 1 ms 588 KB Output is correct
32 Correct 1 ms 588 KB Output is correct
33 Correct 3 ms 696 KB Output is correct
34 Correct 2 ms 588 KB Output is correct
35 Correct 10 ms 1480 KB Output is correct
36 Correct 2 ms 588 KB Output is correct
37 Correct 6 ms 1100 KB Output is correct
38 Correct 10 ms 1612 KB Output is correct
39 Correct 7 ms 972 KB Output is correct
40 Correct 7 ms 1100 KB Output is correct
41 Correct 8 ms 1100 KB Output is correct
42 Correct 6 ms 1100 KB Output is correct
43 Correct 6 ms 1032 KB Output is correct
44 Correct 114 ms 1724 KB Output is correct
45 Correct 16 ms 1740 KB Output is correct
46 Correct 13 ms 1740 KB Output is correct
47 Correct 8 ms 1484 KB Output is correct
48 Correct 10 ms 1728 KB Output is correct
49 Correct 7 ms 1700 KB Output is correct
50 Correct 6 ms 1612 KB Output is correct
51 Correct 12 ms 2216 KB Output is correct
52 Correct 12 ms 2252 KB Output is correct
53 Correct 10 ms 2092 KB Output is correct
54 Correct 1 ms 1228 KB Output is correct
55 Correct 1 ms 1228 KB Output is correct
56 Execution timed out 1088 ms 2696 KB Time limit exceeded
57 Halted 0 ms 0 KB -