Submission #457698

# Submission time Handle Problem Language Result Execution time Memory
457698 2021-08-07T09:58:04 Z elgamalsalman Jakarta Skyscrapers (APIO15_skyscraper) C++14
10 / 100
1 ms 460 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;
vvii adj;
bitset<30'050> visited;

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

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

  cin >> N >> M;
  dogesAt.assign(N + 20, vi());
  adj.assign(M + 20, vii());
  for (int i = 0; i < M; i++) {
    cin >> b[i] >> p[i];
    dogesAt[b[i]].push_back(i);
  }
  
  //cerr << "// adj:-\n";
  //for (int u = 0; u < M; u++) {
  //  cerr << "// " << u << " :";
  //  for (ii v : adj[u]) cerr << " {" << v.fi << ", " << v.se << "}";
  //  cerr << '\n';
  //}
  //cerr << '\n';

  bfs(0);

  //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 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
# 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 Incorrect 1 ms 460 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 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 452 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 Incorrect 1 ms 460 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 460 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 452 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 444 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Incorrect 1 ms 460 KB Output isn't correct
10 Halted 0 ms 0 KB -