Submission #250357

#TimeUsernameProblemLanguageResultExecution timeMemory
250357MarlovJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
1 ms1152 KiB
/* Code by @marlov */ #include <iostream> #include <fstream> #include <string> #include <sstream> #include <vector> #include <string> #include <cmath> #include <algorithm> #include <iomanip> #include <utility> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <stack> #include <queue> #include <iterator> using namespace std; typedef long long ll; typedef pair<int,int> pi; #define INF 200000000 #define maxV 30005 int N,M; pair<int,int> doge[maxV]; int dist[maxV]; vector<int> sat[maxV]; bool visited[maxV]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>N>>M; for(int i=0;i<M;i++){ cin>>doge[i].first>>doge[i].second; dist[i]=INF; sat[doge[i].first].push_back(i); } priority_queue< pair<int,int> > pq; dist[0]=0; pq.push(make_pair(0,0)); while(!pq.empty()){ int cd=pq.top().first; int ci=pq.top().second; pq.pop(); if(visited[ci]) continue; for(int i=doge[ci].first-doge[ci].second;i>=0;i-=doge[ci].second){ if(sat[i].size()>0){ for(int j=0;j<sat[i].size();j++){ if(!visited[sat[i][j]]&&dist[sat[i][j]]>dist[ci]+((doge[ci].first-i)/doge[ci].second)){ dist[sat[i][j]]=dist[ci]+((doge[ci].first-i)/doge[ci].second); pq.push( make_pair(cd+(i-doge[ci].first),sat[i][j])); } } } } for(int i=doge[ci].first+doge[ci].second;i<N;i+=doge[ci].second){ if(sat[i].size()>0){ for(int j=0;j<sat[i].size();j++){ if(!visited[sat[i][j]]&&dist[sat[i][j]]>dist[ci]+((i-doge[ci].first)/doge[ci].second)){ dist[sat[i][j]]=dist[ci]+((i-doge[ci].first)/doge[ci].second); pq.push( make_pair(cd+(doge[ci].first-i),sat[i][j])); } } } } } cout<<dist[1]<<'\n'; return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1,n=0?) * do smth instead of nothing and stay organized */

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:52:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int j=0;j<sat[i].size();j++){
                             ~^~~~~~~~~~~~~~
skyscraper.cpp:62:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int j=0;j<sat[i].size();j++){
                             ~^~~~~~~~~~~~~~
#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...