Submission #119139

#TimeUsernameProblemLanguageResultExecution timeMemory
119139Charis02Jakarta Skyscrapers (APIO15_skyscraper)C++14
100 / 100
819 ms6512 KiB
#include<iostream> #include<stdio.h> #include<vector> #include<cmath> #include<queue> #include<string.h> #include<map> #include<set> #include<algorithm> #define ll long long #define pi pair < ll,ll > #define mp(a,b) make_pair(a,b) #define rep(i,a,b) for(int i = a;i < b;i++) #define N 30004 #define INF 1e9+7 using namespace std; ll pos[N],jump[N],n,m,d[N]; vector < vector < ll > > building(N); int main() { ios_base::sync_with_stdio(false); cin >> n >> m; rep(i,0,m) { cin >> pos[i] >> jump[i]; building[pos[i]].push_back(jump[i]); } rep(i,0,n) d[i] = INF; priority_queue < pi > pq; pq.push(mp(0,pos[0])); d[pos[0]] = 0; while(!pq.empty()) { pi cur = pq.top(); pq.pop(); if(-cur.first > d[cur.second]) continue; rep(i,0,building[cur.second].size()) { ll p = building[cur.second][i]; ll j = -1; while(cur.second + p*j >= 0) { if(-cur.first - j < d[cur.second+p*j]) { d[cur.second+p*j] = -cur.first-j; pq.push(mp(-d[cur.second+p*j],cur.second+p*j)); } j--; } j = 0; while(cur.second + p*j < n) { if(-cur.first + j < d[cur.second+p*j]) { d[cur.second+p*j] = -cur.first+j; pq.push(mp(-d[cur.second+p*j],cur.second+p*j)); } j++; } } } if(d[pos[1]] != INF) cout << d[pos[1]] << endl; else cout << -1 << endl; return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:13:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,a,b) for(int i = a;i < b;i++)
skyscraper.cpp:50:13:
         rep(i,0,building[cur.second].size())
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:50:9: note: in expansion of macro 'rep'
         rep(i,0,building[cur.second].size())
         ^~~
#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...