Submission #369717

#TimeUsernameProblemLanguageResultExecution timeMemory
369717Bill_00Jakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
1107 ms92140 KiB
#include <bits/stdc++.h> #define ff first #define ss second #define mp make_pair #define pb push_back #define pp push #define MOD 1000000007 #define INF 1e18 #define N 30005 #define M 5000000 typedef long long ll; const ll c=174; using namespace std; ll b[N],p[N],path[N]; bool pos[N]; map<ll,bool>pp[N]; vector<pair<ll,ll> >adj[N]; bool vis[N],visited[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n,m; cin >> n >> m; for(ll i=1;i<=m;++i){ cin >> b[i] >> p[i]; if(pp[b[i]][p[i]]!=0){ vis[i]=1; } else{ pos[b[i]]=1; pp[b[i]][p[i]]=1; } } if(b[1]==b[2]){ cout << 0; return 0; } for(ll i=1;i<=m;++i){ if(vis[i]==1) continue; for(ll j=b[i]+p[i];j<n;j+=p[i]){ if(pos[j]) adj[b[i]].pb({j,(j-b[i])/p[i]}); if(pp[j][p[i]]==1) break; } for(ll j=b[i]-p[i];j>=0;j-=p[i]){ if(pos[j]) adj[b[i]].pb({j,(b[i]-j)/p[i]}); if(pp[j][p[i]]==1) break; } } priority_queue<pair<ll,ll> >pq; pq.push({0,b[1]}); while(!pq.empty()){ ll cost=-pq.top().ff; ll doge_id=pq.top().ss; // cout << doge_id <<" " << cost << '\n'; path[doge_id]=cost; pq.pop(); visited[doge_id]=1; for(int i=0;i<adj[doge_id].size();i++){ if(visited[adj[doge_id][i].ff]==0) pq.push({-(cost+adj[doge_id][i].ss),adj[doge_id][i].ff}); } while(!pq.empty() && visited[pq.top().ss]==1) pq.pop(); } if(path[b[2]]==0){ cout << -1; } else cout << path[b[2]]; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:60:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |    for(int i=0;i<adj[doge_id].size();i++){
      |                ~^~~~~~~~~~~~~~~~~~~~
#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...