Submission #452082

#TimeUsernameProblemLanguageResultExecution timeMemory
452082Sarah_MokhtarJakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
282 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 int long long #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; pair<int,int>arr[30005]; vector<pair<int,int>>edges[30005]; vector<int>freq[30005]; int32_t main() { //freopen("dprime.in" , "r" , stdin); Hidden; 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 ; 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 ; 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]=1e18; 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]==1e18) { dist[edges[p.second][i].first] = cost; pq.push({-cost , edges[p.second][i].first}); } } } if(dist[arr[1].first] == 1e18) cout<<"-1"; else cout<<dist[arr[1].first]; }

Compilation message (stderr)

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