Submission #839348

#TimeUsernameProblemLanguageResultExecution timeMemory
839348popovicirobertJakarta Skyscrapers (APIO15_skyscraper)C++14
10 / 100
3 ms464 KiB
#include <bits/stdc++.h> using namespace std; constexpr int MAXN = 30'000; constexpr int MAXP = 30'000; bitset<MAXP + 1> visited[MAXN]; struct Node { short b, p; int dist; }; int main() { #ifdef HOME ifstream cin("input.in"); ofstream cout("output.out"); #endif ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; vector<short> b(m), p(m); vector<short> P(n); for (int i = 0; i < m; i++) { cin >> b[i] >> p[i]; P[b[i]] = p[i]; } queue<Node> Q; Q.push({b[0], p[0], 0}); visited[b[0]][p[0]] = true; while (Q.size()) { auto curr = Q.front(); Q.pop(); auto Go = [&Q](int b, int p, int dist) { if (!visited[b][p]) { Q.push({b, p, dist + 1}); visited[b][p] = true; } }; if (curr.b == b[1]) { cout << curr.dist << "\n"; return 0; } if (curr.b >= curr.p) { Go(curr.b - curr.p, curr.p, curr.dist); } if (curr.b + curr.p < n) { Go(curr.b + curr.p, curr.p, curr.dist); } Go(curr.b, P[curr.b], curr.dist - 1); } cout << -1 << "\n"; return 0; }

Compilation message (stderr)

skyscraper.cpp: In lambda function:
skyscraper.cpp:43:25: warning: narrowing conversion of 'b' from 'int' to 'short int' [-Wnarrowing]
   43 |                 Q.push({b, p, dist + 1});
      |                         ^
skyscraper.cpp:43:28: warning: narrowing conversion of 'p' from 'int' to 'short int' [-Wnarrowing]
   43 |                 Q.push({b, p, dist + 1});
      |                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...