Submission #882679

#TimeUsernameProblemLanguageResultExecution timeMemory
882679NotLinuxJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1054 ms79196 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") // PUT IT BEFORE THE INCLUDE #include <iostream> #include <vector> #include <unordered_set> #include <queue> const unsigned short M = 3e4 + 7; unsigned short n , m; std::pair < int , std::pair < unsigned short , unsigned short > > tmp; void solve(){ std::cin >> n >> m; std::pair < unsigned short , unsigned short > doge[m]; std::vector < unsigned short > root[M]; for(unsigned short i = 0;i<m;i++){ std::cin >> doge[i].first >> doge[i].second; root[doge[i].first].push_back(doge[i].second); } std::unordered_set < unsigned short > vis[n]; std::queue < std::pair < int , std::pair < unsigned short , unsigned short > > > pq;//dist , konum , zıplayış pq.push({0,{doge[0].first,0}}); while(pq.size()){ tmp = pq.front(); pq.pop(); if(vis[tmp.second.first].count(tmp.second.second)){ continue; } if(tmp.second.first == doge[1].first){ std::cout << tmp.first << '\n'; return; } vis[tmp.second.first].insert(tmp.second.second); 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(int itr : root[tmp.second.first]){ 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}}); } } std::cout << -1 << '\n'; } signed main(){ std::ios_base::sync_with_stdio(0);std::cin.tie(0);std::cout.tie(0); 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...