제출 #933340

#제출 시각아이디문제언어결과실행 시간메모리
933340HanksburgerJakarta Skyscrapers (APIO15_skyscraper)C++17
0 / 100
1 ms1368 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<pair<int, int>, int> > vec; priority_queue<pair<int, int> > pq; vector<pair<int, int> > adj[30005]; int dist[30005], final[30005]; vector<int> tmp; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, s, e; cin >> n >> m; for (int i=0; i<m; i++) { int a, b; cin >> a >> b; vec.push_back({{b, a%b}, a}); if (i==0) s=a; if (i==1) e=a; } sort(vec.begin(), vec.end()); for (int i=0; i<vec.size(); i++) { tmp.push_back(vec[i].second); if (i==vec.size()-1 || vec[i].first!=vec[i+1].first) { int a=vec[i].first.first, b=vec[i].first.second, ind=0; for (int j=b; j<n; j+=a) { while (ind<tmp.size() && tmp[ind]<=j) ind++; if (ind==tmp.size()) break; adj[tmp[ind]].push_back({j, (tmp[ind]-j)/a}); } ind=tmp.size()-1; for (int j=(n-b-1)/a*a+b; j>=0; j-=a) { while (ind>=0 && tmp[ind]>=j) ind--; if (ind==-1) break; adj[tmp[ind]].push_back({j, (j-tmp[ind])/a}); } } } for (int i=0; i<n; i++) dist[i]=1e9; dist[s]=0; pq.push({-dist[s], s}); while (!pq.empty()) { int u=pq.top().second; pq.pop(); if (final[u]) continue; final[u]=1; for (int i=0; i<adj[u].size(); i++) { int v=adj[u][i].first, w=adj[u][i].second; if (dist[u]+w<dist[v]) { dist[v]=dist[u]+w; pq.push({-dist[v], v}); } } } if (dist[e]==1e9) cout << -1; else cout << dist[e]; }

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

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:26:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int i=0; i<vec.size(); i++)
      |                   ~^~~~~~~~~~~
skyscraper.cpp:29:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         if (i==vec.size()-1 || vec[i].first!=vec[i+1].first)
      |             ~^~~~~~~~~~~~~~
skyscraper.cpp:34:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |                 while (ind<tmp.size() && tmp[ind]<=j)
      |                        ~~~^~~~~~~~~~~
skyscraper.cpp:36:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |                 if (ind==tmp.size())
      |                     ~~~^~~~~~~~~~~~
skyscraper.cpp:62:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for (int i=0; i<adj[u].size(); i++)
      |                       ~^~~~~~~~~~~~~~
skyscraper.cpp:72:15: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
   72 |     if (dist[e]==1e9)
      |         ~~~~~~^
#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...