Submission #625081

#TimeUsernameProblemLanguageResultExecution timeMemory
625081HanksburgerJakarta Skyscrapers (APIO15_skyscraper)C++17
10 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; queue<pair<pair<int, int>, int> > q; int A[30005], B[30005], C[30005]; map<pair<int, int>, bool> mp; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i=0; i<m; i++) { cin >> A[i] >> B[i]; C[A[i]]=B[i]; } q.push({{A[0], B[0]}, 0}); mp[{A[0], B[0]}]=1; while (!q.empty()) { int a=q.front().first.first, b=q.front().first.second, c=q.front().second; q.pop(); if (a==A[1]) { cout << c; return 0; } if (a+b<n) { if (!mp[{a+b, C[a+b]}]) { q.push({{a+b, C[a+b]}, c+1}); mp[{a+b, C[a+b]}]=1; } if (!mp[{a+b, b}]) { q.push({{a+b, b}, c+1}); mp[{a+b, b}]=1; } } if (a-b>=0) { if (!mp[{a-b, C[a-b]}]) { q.push({{a-b, C[a-b]}, c+1}); mp[{a-b, C[a-b]}]=1; } if (!mp[{a-b, b}]) { q.push({{a-b, b}, c+1}); mp[{a-b, b}]=1; } } } cout << -1; return 0; }
#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...