Submission #456455

# Submission time Handle Problem Language Result Execution time Memory
456455 2021-08-06T19:18:22 Z elgamalsalman Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
654 ms 262148 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 vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

int N, M, b[60'050], p[60'050];
ll sssp[60'050];
vvi dogesAt;
vvii adj;

void dijkstra(int source) {
  memset(sssp, -1, sizeof sssp);
  priority_queue<llll> pq;
  pq.push({0, source});
  while (!pq.empty()) {
    llll u = pq.top(); pq.pop();
    u.ww = -u.ww;
    //cerr << "// pq.top() : {" << u.fi << ", " << u.se << "}\n";
    if (sssp[u.vv] != -1 && sssp[u.vv] <= u.ww) continue;
    sssp[u.vv] = u.ww;
    for (ii v : adj[u.vv]) {
      ll newDis = u.ww + v.ww;
      if (sssp[v.vv] == -1 || sssp[v.vv] > newDis) {
	pq.push({-newDis, v.vv});
      }
    }
  }
}

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

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

  for (int i = 0; i < M; i++) {
    for (int j = b[i], stepCount = 0; j < N; j += p[i], stepCount++) {
      for (int d : dogesAt[j]) adj[i].push_back({stepCount, d});
    }

    for (int j = b[i] - p[i], stepCount = 1; j >= 0; j -= p[i], stepCount++) {
      for (int d : dogesAt[j]) adj[i].push_back({stepCount, d});
    }
  }

  //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';

  dijkstra(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 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 2 ms 972 KB Output is correct
11 Correct 24 ms 5184 KB Output is correct
12 Correct 460 ms 49320 KB Output is correct
13 Correct 465 ms 49472 KB Output is correct
14 Correct 15 ms 3404 KB Output is correct
15 Correct 15 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 24 ms 5152 KB Output is correct
12 Correct 459 ms 49228 KB Output is correct
13 Correct 515 ms 49424 KB Output is correct
14 Correct 15 ms 3404 KB Output is correct
15 Correct 15 ms 3404 KB Output is correct
16 Correct 1 ms 1100 KB Output is correct
17 Correct 8 ms 2120 KB Output is correct
18 Correct 2 ms 844 KB Output is correct
19 Correct 1 ms 844 KB Output is correct
20 Correct 476 ms 49532 KB Output is correct
21 Correct 1 ms 844 KB Output is correct
22 Correct 1 ms 844 KB Output is correct
23 Correct 2 ms 972 KB Output is correct
24 Correct 3 ms 1228 KB Output is correct
25 Correct 3 ms 1100 KB Output is correct
26 Correct 436 ms 46560 KB Output is correct
27 Correct 429 ms 47332 KB Output is correct
28 Correct 2 ms 1228 KB Output is correct
29 Correct 3 ms 1228 KB Output is correct
30 Correct 1 ms 844 KB Output is correct
31 Correct 2 ms 972 KB Output is correct
32 Correct 1 ms 972 KB Output is correct
33 Correct 15 ms 3396 KB Output is correct
34 Correct 16 ms 3396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 2 ms 972 KB Output is correct
11 Correct 24 ms 5184 KB Output is correct
12 Correct 468 ms 49288 KB Output is correct
13 Correct 460 ms 49528 KB Output is correct
14 Correct 14 ms 3404 KB Output is correct
15 Correct 15 ms 3412 KB Output is correct
16 Correct 1 ms 1100 KB Output is correct
17 Correct 9 ms 2120 KB Output is correct
18 Correct 1 ms 844 KB Output is correct
19 Correct 1 ms 844 KB Output is correct
20 Correct 439 ms 49532 KB Output is correct
21 Correct 1 ms 844 KB Output is correct
22 Correct 1 ms 844 KB Output is correct
23 Correct 1 ms 972 KB Output is correct
24 Correct 3 ms 1228 KB Output is correct
25 Correct 2 ms 1100 KB Output is correct
26 Correct 397 ms 46648 KB Output is correct
27 Correct 400 ms 47320 KB Output is correct
28 Correct 2 ms 1228 KB Output is correct
29 Correct 3 ms 1228 KB Output is correct
30 Correct 1 ms 844 KB Output is correct
31 Correct 2 ms 972 KB Output is correct
32 Correct 1 ms 844 KB Output is correct
33 Correct 15 ms 3476 KB Output is correct
34 Correct 15 ms 3396 KB Output is correct
35 Correct 431 ms 64092 KB Output is correct
36 Correct 12 ms 2668 KB Output is correct
37 Correct 494 ms 65552 KB Output is correct
38 Correct 628 ms 72556 KB Output is correct
39 Correct 651 ms 74772 KB Output is correct
40 Correct 640 ms 73440 KB Output is correct
41 Correct 587 ms 72028 KB Output is correct
42 Runtime error 454 ms 262148 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 2 ms 972 KB Output is correct
11 Correct 24 ms 5184 KB Output is correct
12 Correct 455 ms 49276 KB Output is correct
13 Correct 453 ms 49456 KB Output is correct
14 Correct 14 ms 3404 KB Output is correct
15 Correct 15 ms 3364 KB Output is correct
16 Correct 2 ms 1100 KB Output is correct
17 Correct 7 ms 2120 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 844 KB Output is correct
20 Correct 434 ms 49668 KB Output is correct
21 Correct 1 ms 844 KB Output is correct
22 Correct 1 ms 844 KB Output is correct
23 Correct 1 ms 972 KB Output is correct
24 Correct 3 ms 1228 KB Output is correct
25 Correct 2 ms 1100 KB Output is correct
26 Correct 395 ms 46448 KB Output is correct
27 Correct 402 ms 47388 KB Output is correct
28 Correct 2 ms 1228 KB Output is correct
29 Correct 4 ms 1228 KB Output is correct
30 Correct 1 ms 844 KB Output is correct
31 Correct 2 ms 972 KB Output is correct
32 Correct 1 ms 844 KB Output is correct
33 Correct 15 ms 3396 KB Output is correct
34 Correct 15 ms 3492 KB Output is correct
35 Correct 468 ms 64128 KB Output is correct
36 Correct 12 ms 2668 KB Output is correct
37 Correct 497 ms 65520 KB Output is correct
38 Correct 624 ms 72580 KB Output is correct
39 Correct 654 ms 74760 KB Output is correct
40 Correct 648 ms 73568 KB Output is correct
41 Correct 591 ms 72048 KB Output is correct
42 Runtime error 462 ms 262148 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -