Submission #666176

#TimeUsernameProblemLanguageResultExecution timeMemory
666176ParsaSJakarta Skyscrapers (APIO15_skyscraper)C++17
100 / 100
108 ms6548 KiB
// In the name of God #include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define mp make_pair typedef long long ll; const int N = 3e4 + 5; int n, m; int dis[N]; unordered_set<int> S[N]; bool vis[N]; void solve() { cin >> n >> m; int s = -1, t = -1; memset(dis, 63, sizeof dis); for (int i = 0; i < m; i++) { int b, p; cin >> b >> p; if (s != -1 && t == -1) t = b; if (s == -1) s = b; S[b].insert(p); } priority_queue<pair<int, int> > pq; pq.push(mp(0, s)); dis[s] = 0; while (!pq.empty()) { int i = pq.top().se; pq.pop(); if (vis[i]) continue; vis[i] = true; int prv = -1; for (auto p : S[i]) { for (int j = i + p; j < n; j += p) { //cout << "check " << j << ' ' << dis[j] << '-' << dis[i] + (j - i) / p << endl; if (dis[j] > dis[i] + (j - i) / p) { dis[j] = dis[i] + (j - i) / p; pq.push(mp(-dis[j], j)); } if (S[j].count(p)) break; } for (int j = i - p; j >= 0; j -= p) { //cout << "check " << j << ' ' << dis[j] << '-' << dis[i] + (i - j) / p << endl; if (dis[j] > dis[i] + (i - j) / p) { dis[j] = dis[i] + (i - j) / p; pq.push(mp(-dis[j], j)); } if (S[j].count(p)) break; } } } cout << (dis[t] < 1e9 ? dis[t] : -1) << '\n'; } int32_t main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); solve(); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:36:13: warning: unused variable 'prv' [-Wunused-variable]
   36 |         int prv = -1;
      |             ^~~
#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...