이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// PUT IT BEFORE THE INCLUDE
#include <bits/stdc++.h>
using namespace std;
const short M = 3e4 + 7;
void solve(){
short n, m;
cin >> n >> m;
pair < short , short > doge[m];
vector < short > root[M];
for(short i = 0;i<m;i++){
cin >> doge[i].first >> doge[i].second;
root[doge[i].first].push_back(doge[i].second);
}
unordered_set < short > vis[n];
queue < pair < int , pair < short , short > > > pq;//dist , konum , zıplayış
pq.push({0,{doge[0].first,0}});
while(pq.size()){
pair < int , pair < short , short > > tmp = pq.front();
pq.pop();
if(vis[tmp.second.first].count(tmp.second.second)){
continue;
}
if(tmp.second.first == doge[1].first){
cout << tmp.first << endl;
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(auto 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}});
}
}
cout << -1 << endl;
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
short testcase = 1;//cin >> testcase;
while(testcase--)solve();
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |