Submission #882708

#TimeUsernameProblemLanguageResultExecution timeMemory
882708NotLinuxJakarta Skyscrapers (APIO15_skyscraper)C++17
100 / 100
497 ms175884 KiB
#include <bits/stdc++.h> using namespace std; const int M = 3e4 + 7; bitset < 30007 > vis[M]; void solve(){ int n, m; cin >> n >> m; pair < int , int > doge[m]; vector < int > root[M]; for(int i = 0;i<m;i++){ cin >> doge[i].first >> doge[i].second; root[doge[i].first].push_back(doge[i].second); } queue < pair < int , pair < int , int > > > pq;//dist , konum , zıplayış pq.push({0,{doge[0].first,0}}); while(pq.size()){ pair < int , pair < int , int > > tmp = pq.front(); pq.pop(); if(vis[tmp.second.first][tmp.second.second] == 1){ continue; } if(tmp.second.first == doge[1].first){ cout << tmp.first << '\n'; return; } vis[tmp.second.first][tmp.second.second] = 1; if(tmp.second.first + tmp.second.second < n)pq.push({tmp.first + 1 , {tmp.second.first + tmp.second.second , tmp.second.second}}); if(tmp.second.first - tmp.second.second >= 0)pq.push({tmp.first + 1 , {tmp.second.first - tmp.second.second , tmp.second.second}}); for(auto itr : root[tmp.second.first]){ if(itr == tmp.second.second)continue; if(tmp.second.first + itr < n)pq.push({tmp.first + 1 , {tmp.second.first + itr , itr}}); if(tmp.second.first - itr >= 0)pq.push({tmp.first + 1 , {tmp.second.first - itr , itr}}); } } cout << -1 << '\n'; } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int testcase = 1;//cin >> testcase; while(testcase--)solve(); }
#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...