Submission #786120

# Submission time Handle Problem Language Result Execution time Memory
786120 2023-07-18T04:13:14 Z makanhulia Jakarta Skyscrapers (APIO15_skyscraper) C++17
36 / 100
1000 ms 31068 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll MAXN = 3e4 + 5;

ll n, m, ans = -1, awal, tujuan;

vector<ll> baris[MAXN];
// bool visited[MAXN][MAXN];
map<pll, bool> visited;

void bfs() {
  queue<pair<pll, ll>> que;
  // {{Idx Baris, Lompat}, Dist}

  for (int i = 0; i < baris[awal].size(); ++i)
  {
    que.push({{awal, baris[awal][i]}, 0});
  }

  while(!que.empty()) {
    pair<pll, ll> now = que.front();
    // {{Idx Baris, Lompat}, Dist}
    que.pop();

    if (visited[now.first])
    {
      continue ;
    }
    visited[now.first] = true;

    if (now.first.first == tujuan)
    {
      ans = now.second;
      return ;
    }

    ll lompat = now.first.second;
    ll nxt = now.first.first + lompat;

    if (nxt < n && !visited[{nxt, lompat}])
    {
      que.push({{nxt, lompat}, now.second+1});
    }

    nxt = now.first.first - lompat;
    if (nxt >= 0 && !visited[{nxt, lompat}])
    {
      que.push({{nxt, lompat}, now.second+1});
    }

    vector<ll> barisNow = baris[now.first.first];
    for (int i = 0; i < barisNow.size(); ++i)
    {
      lompat = barisNow[i];
      nxt = now.first.first + lompat;

      if (nxt < n && !visited[{nxt, lompat}])
      {
        que.push({{nxt, lompat}, now.second+1});
      }

      nxt = now.first.first - lompat;
      if (nxt >= 0 && !visited[{nxt, lompat}])
      {
        que.push({{nxt, lompat}, now.second+1});
      }
    }
  }
}

int main(){
  cin >> n >> m;
  for (int i = 0; i < m; ++i)
  {
    ll tmpa, tmpb;
    cin >> tmpa >> tmpb;
    baris[tmpa].push_back(tmpb);

    if (i == 0) {
      awal = tmpa;
    } else if (i == 1) {
      tujuan = tmpa;
    }
  }

  bfs();

  cout << ans << "\n";
  return 0;
}

Compilation message

skyscraper.cpp: In function 'void bfs()':
skyscraper.cpp:17:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |   for (int i = 0; i < baris[awal].size(); ++i)
      |                   ~~^~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i = 0; i < barisNow.size(); ++i)
      |                     ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 9 ms 1632 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 9 ms 1620 KB Output is correct
15 Correct 3 ms 1236 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 3 ms 1364 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 2 ms 1108 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 3 ms 1236 KB Output is correct
24 Correct 5 ms 1364 KB Output is correct
25 Correct 2 ms 980 KB Output is correct
26 Correct 2 ms 1108 KB Output is correct
27 Correct 3 ms 1236 KB Output is correct
28 Correct 11 ms 2132 KB Output is correct
29 Correct 41 ms 4700 KB Output is correct
30 Correct 9 ms 2004 KB Output is correct
31 Correct 16 ms 3008 KB Output is correct
32 Correct 11 ms 2420 KB Output is correct
33 Correct 85 ms 8524 KB Output is correct
34 Correct 45 ms 5036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 9 ms 1620 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 3 ms 1364 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 2 ms 1108 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 4 ms 1220 KB Output is correct
24 Correct 5 ms 1364 KB Output is correct
25 Correct 2 ms 980 KB Output is correct
26 Correct 2 ms 1108 KB Output is correct
27 Correct 3 ms 1236 KB Output is correct
28 Correct 11 ms 2184 KB Output is correct
29 Correct 41 ms 4940 KB Output is correct
30 Correct 8 ms 2004 KB Output is correct
31 Correct 16 ms 3028 KB Output is correct
32 Correct 12 ms 2480 KB Output is correct
33 Correct 87 ms 8484 KB Output is correct
34 Correct 44 ms 5024 KB Output is correct
35 Correct 37 ms 5308 KB Output is correct
36 Correct 3 ms 1108 KB Output is correct
37 Correct 13 ms 2984 KB Output is correct
38 Correct 25 ms 4280 KB Output is correct
39 Correct 11 ms 1364 KB Output is correct
40 Correct 11 ms 1436 KB Output is correct
41 Correct 12 ms 1828 KB Output is correct
42 Correct 12 ms 1364 KB Output is correct
43 Correct 11 ms 1488 KB Output is correct
44 Correct 12 ms 2256 KB Output is correct
45 Execution timed out 1095 ms 31068 KB Time limit exceeded
46 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 3 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 8 ms 1620 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 3 ms 1364 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 2 ms 1108 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 3 ms 1260 KB Output is correct
24 Correct 5 ms 1440 KB Output is correct
25 Correct 2 ms 980 KB Output is correct
26 Correct 2 ms 1108 KB Output is correct
27 Correct 3 ms 1236 KB Output is correct
28 Correct 13 ms 2132 KB Output is correct
29 Correct 35 ms 4748 KB Output is correct
30 Correct 8 ms 2004 KB Output is correct
31 Correct 16 ms 2972 KB Output is correct
32 Correct 11 ms 2388 KB Output is correct
33 Correct 98 ms 8632 KB Output is correct
34 Correct 53 ms 5012 KB Output is correct
35 Correct 37 ms 5240 KB Output is correct
36 Correct 3 ms 1108 KB Output is correct
37 Correct 14 ms 3028 KB Output is correct
38 Correct 25 ms 4168 KB Output is correct
39 Correct 11 ms 1364 KB Output is correct
40 Correct 11 ms 1472 KB Output is correct
41 Correct 12 ms 1748 KB Output is correct
42 Correct 10 ms 1364 KB Output is correct
43 Correct 11 ms 1500 KB Output is correct
44 Correct 12 ms 2320 KB Output is correct
45 Execution timed out 1083 ms 29340 KB Time limit exceeded
46 Halted 0 ms 0 KB -