제출 #402538

#제출 시각아이디문제언어결과실행 시간메모리
402538faresbasbsJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
1 ms972 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; bitset<30001> bs,bs2[30001]; vector<int> v[30001]; int n,m; int main(){ ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); cin >> n >> m; for(int i = 0 ; i < m ; i += 1){ int a,b; cin >> a >> b; v[a].push_back(b); } queue<pair<int,int>> q; for(auto i : v[0]){ q.push({0,i}); bs2[0][i] = 1; } bs[0] = 1; int dist = 0; while(q.size()){ queue<pair<int,int>> q2; while(q.size()){ pair<int,int> a = q.front(); q.pop(); cout << a.first << " " << a.second << " " << dist << endl; if(!bs[a.first]){ bs[a.first] = 1; for(auto i : v[a.first]){ q.push({a.first,i}) , bs2[a.first][i] = 1; } } if(a.first+a.second < n && !bs2[a.first+a.second][a.second]){ q2.push({a.first+a.second,a.second}) , bs2[a.first+a.second][a.second] = 1; } if(a.first-a.second >= 0 && !bs2[a.first-a.second][a.second]){ q2.push({a.first-a.second,a.second}) , bs2[a.first-a.second][a.second] = 1; } } q = q2; if(bs[1]){ cout << dist << '\n'; return 0; } dist += 1; } cout << -1 << endl; }
#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...