Submission #452089

#TimeUsernameProblemLanguageResultExecution timeMemory
452089Sarah_MokhtarJakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
546 ms262148 KiB
//Sorry but iam targeting IOI :)) //NEVER LOSE HOPE #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> #define endl "\n" #define ceil(a,b) (a+(b-1))/b #define all(v) v.begin(),v.end() #define Hidden ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); using namespace std; const int mod = 1e9+7; int32_t main() { Hidden; pair<int,int>arr[30005]; vector<pair<int,int>>edges[30005]; vector<int>freq[30005]; int n, m; cin >> n >> m; for(int i = 0 ; i < m ; i ++) { int b , p; cin>>b>>p; arr[i]={b,p}; freq[b].push_back(i); } for(int i = 0 ; i < m ; i++) { for(int j = arr[i].first+arr[i].second ; j<=n ; j+=arr[i].second) { for(int p = 0 ; p < freq[j].size() ; p ++) { edges[arr[i].first].push_back({arr[freq[j][p]].first ,(j-arr[i].first)/arr[i].second}); } } for(int j = arr[i].first-arr[i].second ; j>=0 ; j-=arr[i].second) { for(int p = 0 ; p < freq[j].size() ; p ++) { edges[arr[i].first].push_back({arr[freq[j][p]].first ,(arr[i].first-j)/arr[i].second}); } } } priority_queue<pair<int,int>>pq; pq.push({0,arr[0].first}); int dist[30005]; for(int i = 0 ; i < 30005 ; i++) dist[i]=INT_MAX; dist[arr[0].first]=0; while(!pq.empty()) { pair<int,int>p=pq.top(); pq.pop(); for(int i = 0; i < edges[p.second].size() ; i++) { int cost=dist[p.second]+edges[p.second][i].second; if(dist[edges[p.second][i].first] > cost||dist[edges[p.second][i].first]==INT_MAX) { dist[edges[p.second][i].first] = cost; pq.push({-cost , edges[p.second][i].first}); } } } if(dist[arr[1].first] == INT_MAX) cout<<"-1"; else cout<<dist[arr[1].first]; }

Compilation message (stderr)

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:31:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for(int p = 0 ; p < freq[j].size() ; p ++)
      |                         ~~^~~~~~~~~~~~~~~~
skyscraper.cpp:38:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for(int p = 0 ; p < freq[j].size() ; p ++)
      |                         ~~^~~~~~~~~~~~~~~~
skyscraper.cpp:55:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int i = 0; i < edges[p.second].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...