Submission #452075

#TimeUsernameProblemLanguageResultExecution timeMemory
452075Sarah_MokhtarJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
2 ms1868 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 N=3e4+10,mod = 1e9+7; pair<int,int>arr[N]; vector<pair<int,int>>edges[N]; vector<int>freq[N]; int32_t main() { //freopen("dprime.in" , "r" , stdin); 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) { if(j==0) continue; 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) { if(j==0) continue; 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[N]; for(int i = 0 ; i < N ; i++) dist[i]=1e15; 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] = 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: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:41: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]
   41 |       for(int p = 0 ; p < freq[j].size() ; p ++)
      |                       ~~^~~~~~~~~~~~~~~~
skyscraper.cpp:58: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]
   58 |     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...