Submission #231953

#TimeUsernameProblemLanguageResultExecution timeMemory
231953peijarJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
63 ms33656 KiB
#include <bits/stdc++.h> using namespace std; #define SZ(v) ((int)(v).size()) using ll = long long; const int MAX = 2000; int dis[MAX][MAX]; 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; for (int i(0); i < MAX; ++i) for (int j(0); j < MAX; ++j) dis[i][j] = 1e9; 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[pos-type][type] == 1e9) { dis[pos - type][type] = 1 + cur.get(); pq.push({pos - type, type}); } if (pos + type < len_route and dis[pos+type][type] == 1e9) { 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...