제출 #545743

#제출 시각아이디문제언어결과실행 시간메모리
545743AJ00Jakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
327 ms262144 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; vector<vector<pair<int,int>>> adj(30000); signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int t=1,n,k,st,fin; cin >> n >> k; pair<int,int> doge[k]; vector<set<int>> doges(n); vector<int> dist(n); // memset(dist, 0x3f, sizeof dist); for (int i = 0; i < k; i++){ cin >> doge[i].first >> doge[i].second; doges[doge[i].first].insert(doge[i].second); if (i == 0){ st = doge[i].first; } if (i == 1){ fin = doge[i].first; } } sort(doge,doge+k); for (int i = 0; i < k; i++){ for (int j = doge[i].first+doge[i].second; j < n; j += doge[i].second){ adj[doge[i].first].push_back({j,((j-doge[i].first)/doge[i].second)}); if (doges[j].find(doge[i].second) != doges[j].end()){ break; } } for (int j = doge[i].first-doge[i].second; j >= 0; j -= doge[i].second){ adj[doge[i].first].push_back({j,((doge[i].first-j)/doge[i].second)}); if (doges[j].find(doge[i].second) != doges[j].end()){ break; } } } for (int i = 0; i < n; i++){ dist[i] = INF; } priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq; pq.push({0,st}); dist[st] = 0; while(!pq.empty()){ int distp = pq.top().first; int p = pq.top().second; pq.pop(); if (distp != dist[p]){ continue; } for (auto ch: adj[p]){ if (dist[p] + ch.second < dist[ch.first]){ dist[ch.first] = dist[p] + ch.second; pq.push({dist[ch.first],ch.first}); } } } dist[fin] >= INF ? cout << "-1\n" : cout << dist[fin] << "\n"; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:9:9: warning: unused variable 't' [-Wunused-variable]
    9 |     int t=1,n,k,st,fin;
      |         ^
skyscraper.cpp:45:12: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |     dist[st] = 0;
      |            ^
skyscraper.cpp:60:13: warning: 'fin' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |     dist[fin] >= INF ? cout << "-1\n" : cout << dist[fin] << "\n";
      |             ^
#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...