Submission #231954

#TimeUsernameProblemLanguageResultExecution timeMemory
231954peijarJakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
1099 ms16224 KiB
#include <bits/stdc++.h> using namespace std; #define SZ(v) ((int)(v).size()) using ll = long long; const int MAX = 2000; map<pair<int, int>, int> dis; vector<int> types[MAX]; struct Etat { int pos, last_type; int get() const { return dis[{pos, last_type}]; } }; int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int nb_doge, len_route; cin >> len_route >> nb_doge; vector<pair<int, int> > doge(nb_doge); for (auto &[building, skip] : doge) { cin >> building >> skip; types[building].push_back(skip); } int target = doge[1].first; queue<Etat> pq; dis[{doge[0].first, doge[0].second}] = 0; pq.push({doge[0].first, doge[0].second}); while (SZ(pq)) { Etat cur = pq.front(); pq.pop(); auto [pos, last_type] = cur; if (pos == target) { cout << cur.get() << endl; return 0; } types[pos].push_back(last_type); for (auto type : types[pos]) { if (pos >= type and !dis.count({pos-type, type})) { dis[{pos - type, type}] = 1 + cur.get(); pq.push({pos - type, type}); } if (pos + type < len_route and !dis.count({pos+type, type})) { dis[{pos+type, type}] = 1 + cur.get(); pq.push({pos+type, type}); } } types[pos].pop_back(); } 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...