Submission #457935

# Submission time Handle Problem Language Result Execution time Memory
457935 2021-08-07T15:04:06 Z elgamalsalman Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 2904 KB
#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 1 ms 456 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 1 ms 456 KB Output is correct
6 Correct 1 ms 452 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 596 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 456 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 456 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 596 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 2 ms 588 KB Output is correct
18 Correct 1 ms 584 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 45 ms 716 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 2 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 2 ms 588 KB Output is correct
33 Correct 3 ms 588 KB Output is correct
34 Correct 3 ms 716 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 456 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 580 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 592 KB Output is correct
20 Correct 46 ms 728 KB Output is correct
21 Correct 1 ms 592 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 588 KB Output is correct
24 Correct 1 ms 592 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 600 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 2 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 588 KB Output is correct
34 Correct 2 ms 588 KB Output is correct
35 Correct 8 ms 1612 KB Output is correct
36 Correct 2 ms 720 KB Output is correct
37 Correct 6 ms 1228 KB Output is correct
38 Correct 9 ms 1884 KB Output is correct
39 Correct 8 ms 1228 KB Output is correct
40 Correct 8 ms 1364 KB Output is correct
41 Correct 10 ms 1376 KB Output is correct
42 Correct 6 ms 1232 KB Output is correct
43 Correct 6 ms 1236 KB Output is correct
44 Correct 103 ms 1948 KB Output is correct
45 Correct 18 ms 1868 KB Output is correct
46 Correct 13 ms 1860 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 588 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 588 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 584 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 46 ms 724 KB Output is correct
21 Correct 1 ms 592 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 2 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 3 ms 588 KB Output is correct
34 Correct 2 ms 588 KB Output is correct
35 Correct 9 ms 1740 KB Output is correct
36 Correct 2 ms 716 KB Output is correct
37 Correct 6 ms 1272 KB Output is correct
38 Correct 9 ms 1868 KB Output is correct
39 Correct 8 ms 1228 KB Output is correct
40 Correct 8 ms 1356 KB Output is correct
41 Correct 8 ms 1464 KB Output is correct
42 Correct 6 ms 1228 KB Output is correct
43 Correct 6 ms 1228 KB Output is correct
44 Correct 106 ms 1944 KB Output is correct
45 Correct 17 ms 1964 KB Output is correct
46 Correct 13 ms 1868 KB Output is correct
47 Correct 8 ms 1620 KB Output is correct
48 Correct 7 ms 1868 KB Output is correct
49 Correct 9 ms 2000 KB Output is correct
50 Correct 5 ms 1740 KB Output is correct
51 Correct 13 ms 2508 KB Output is correct
52 Correct 12 ms 2508 KB Output is correct
53 Correct 10 ms 2336 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 1090 ms 2904 KB Time limit exceeded
57 Halted 0 ms 0 KB -