제출 #882567

#제출 시각아이디문제언어결과실행 시간메모리
882567vjudge1Jakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
643 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int inf = 1e18 + 7; const int M = 3e4; struct cmp{ bool operator()(array < int , 3 > const& a , array < int , 3 > const& b){ return b[0] < a[0]; } }; 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); } set < pair < int , int > > vis;//konum zıplayış priority_queue < array < int , 3 > , vector < array < int , 3 > > , cmp > pq;//dist , konum , zıplayış pq.push({0,doge[0].first,0}); while(pq.size()){ array < int , 3 > tmp = pq.top(); pq.pop(); if(tmp[1] < 0 or tmp[1] >= n or vis.count({tmp[1],tmp[2]})){ //cout << "rejected : " << tmp[0] << " " << tmp[1] << " " << tmp[2] << " because " << (tmp[1] < 0) << (tmp[1] >= n) << vis.count({tmp[1],tmp[2]}) <<endl; continue; } //cout << tmp[0] << " " << tmp[1] << " " << tmp[2] << endl; if(tmp[1] == doge[1].first){ cout << tmp[0] << endl; return; } vis.insert({tmp[1],tmp[2]}); pq.push({tmp[0] + 1 , tmp[1] + tmp[2] , tmp[2]}); //cout << "-> " << tmp[0] + 1 << " " << tmp[1] + tmp[2] << " " << tmp[2] << endl; pq.push({tmp[0] + 1 , tmp[1] - tmp[2] , tmp[2]}); //cout << "-> " << tmp[0] + 1 << " " << tmp[1] - tmp[2] << " " << tmp[2] << endl; for(auto itr : root[tmp[1]]){ pq.push({tmp[0] + 1 , tmp[1] + itr , itr}); //cout << "-> " << tmp[0] + 1 << " " << tmp[1] + itr << " " << itr << endl; pq.push({tmp[0] + 1 , tmp[1] - itr , itr}); //cout << "-> " << tmp[0] + 1 << " " << tmp[1] - itr << " " << itr << endl; } } cout << -1 << endl; } signed main(){ ios_base::sync_with_stdio(0);cin.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...