Submission #1037625

#TimeUsernameProblemLanguageResultExecution timeMemory
1037625MuhammetJakarta Skyscrapers (APIO15_skyscraper)C++17
0 / 100
1 ms604 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int #define sz(x) (int)x.size() #define ff first #define ss second const ll N = 30002; ll T, n, m, dis[N]; vector <int> v1; pair<int,int> a[N]; set <int> v; int main(){ // ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for(int i = 0; i < m; i++){ cin >> a[i].ff >> a[i].ss; if(a[i].ff != a[0].ff){ v.insert(a[i].ff); } } int ind = a[0].ff, p = a[1].ff; sort (a,a+m); for(int i = 0; i <= n; i++) dis[i] = 1e9; dis[ind] = 0; for(int i = 0; i < m; i++){ if(a[i].ff == ind){ if(sz(v1) > 0 and a[i].ss == v1.back()) continue; v1.push_back(a[i].ss); } } while(sz(v) > 0){ int mn = 1e9, k = -1, cnt = 0, b = 0; for(auto i : v1){ for(auto j : v){ if(dis[j] < mn){ mn = dis[j]; k = j; } if(abs(j-ind) % i != 0) continue; dis[j] = min(dis[j],dis[ind]+abs(j-ind)/i); if(dis[j] < mn){ mn = dis[j]; k = j; } } } v1.clear(); int l = 0, r = m-1, x; while(l <= r){ int md = (l + r) / 2; if(a[md].ff >= k){ x = md; r = md-1; } else { l = md+1; } } ind = k; for(int i = x; i < m; i++){ if(a[i].ff == ind){ if(sz(v1) > 0 and a[i].ss == v1.back()) continue; v1.push_back(a[i].ss); } else break; } v.erase(v.find(ind)); if(ind == p) break; } cout << dis[p]; return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:47:31: warning: unused variable 'cnt' [-Wunused-variable]
   47 |         int mn = 1e9, k = -1, cnt = 0, b = 0;
      |                               ^~~
skyscraper.cpp:47:40: warning: unused variable 'b' [-Wunused-variable]
   47 |         int mn = 1e9, k = -1, cnt = 0, b = 0;
      |                                        ^
skyscraper.cpp:75:24: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   75 |         for(int i = x; i < m; 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...