Submission #396690

#TimeUsernameProblemLanguageResultExecution timeMemory
396690leinad2Jakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1077 ms77132 KiB
#include<bits/stdc++.h> using namespace std; int n, m, i, j, k, A[30010], a, b, w, s, e, B[30010][2]; vector<pair<int, int> >adj[30010]; map<int, int>mp[30010]; map<int, int>::iterator it; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > >pq; main() { ios_base::sync_with_stdio(!cin.tie(NULL)); for(cin>>n>>m;i++<m;) { cin>>B[i][0]>>B[i][1]; mp[B[i][1]][B[i][0]]++; } for(i=0;i++<30000;) { for(it=mp[i].begin();it!=mp[i].end();it++) { j=it->first; a=1; for(k=j+i;k<n;k+=i,a++) { adj[j].push_back({k, a}); if(mp[i].find(k)!=mp[i].end())break; } a=1; for(k=j-i;k>=0;k-=i,a++) { adj[j].push_back({k, a}); if(mp[i].find(k)!=mp[i].end())break; } } } s=B[1][0];e=B[2][0]; for(i=0;i<n;i++)A[i]=1e9; pq.push({0, s}); while(pq.size()) { pair<int, int>p=pq.top();pq.pop(); a=p.second;b=p.first; if(A[a]<1e9)continue; A[a]=b; for(i=0;i<adj[a].size();i++) { pq.push({A[a]+adj[a][i].second, adj[a][i].first}); } } if(A[e]==1e9)A[e]=-1;cout<<A[e]; }

Compilation message (stderr)

skyscraper.cpp:8:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      |      ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for(i=0;i<adj[a].size();i++)
      |                 ~^~~~~~~~~~~~~~
skyscraper.cpp:49:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   49 |     if(A[e]==1e9)A[e]=-1;cout<<A[e];
      |     ^~
skyscraper.cpp:49:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   49 |     if(A[e]==1e9)A[e]=-1;cout<<A[e];
      |                          ^~~~
#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...