Submission #397318

#TimeUsernameProblemLanguageResultExecution timeMemory
397318BitmaskingJakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
215 ms262148 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define f(i,a,b) for( ll i = a; i < b ; i++ ) #define af(i,a,b) for( ll i = a; i >= b ; i--) #define rep(i,a,b,k) for(ll i = a; i < b ; i+= k ) #define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k) #define ones(ini) (ll) __builtin_popcountll(x) #define cuantos(a,x) count(all(a),x) #define fs first #define sc second #define pb push_back #define po pop_back #define sz(a) (ll) a.size() #define all(a) a.begin(), a.end() #define sor(a) sort( a.begin(), a.end() ) #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr) #define watch(x) cout << (#x) << " is " << (x) <<"\n" #define test ll deftestcases;cin>>deftestcases;while(deftestcases--) #define PI acos(-1) using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; template<class T> using ordered_set =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ; const ll inf = 2e18; const ll mod = 1e9+7; const ll MAX = 1e5+10; vii adj[MAX]; vi aux[MAX]; ll dis[MAX]; void dijkstra(ll root,ll n){ f(i,0,n+4){ dis[i] = -1; } priority_queue<ii,vii,greater<ii>> pq; dis[root] = 0; pq.push({dis[root],root}); while(sz(pq)){ ll u = pq.top().sc; ll d = pq.top().fs; pq.pop(); if(dis[u]!=d) continue; for(auto v : adj[u]){ ll to = v.fs,w = v.sc; if(dis[to]==-1 || dis[u]+w<dis[to]){ dis[to] = dis[u]+w; pq.push({dis[to],to}); } } } } void ida(ll u,ll n){ for(auto pod : aux[u]){ ll to = 0,mul=1; while(to<=n){ to = pod*mul+u; if(to>=n) break; adj[u].pb({to,mul}); mul++; } } } void vuelta(ll u){ for(auto pod : aux[u]){ ll to = 0,mul=1; while(to>=0){ to = u-pod*mul; if(to<0) break; adj[u].pb({to,mul}); mul++; } } } int main(){ fastio; ll n,m;cin>>n>>m; ll ini,meta; f(i,0,m){ ll b,p;cin>>b>>p; if(!i) ini = b; if(i==1) meta = b; aux[b].pb(p); } f(u,0,n){ ida(u,n); vuelta(u); } dijkstra(ini,n); cout<<dis[meta]<<"\n"; return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:97:19: warning: 'meta' may be used uninitialized in this function [-Wmaybe-uninitialized]
   97 |     cout<<dis[meta]<<"\n";
      |                   ^
skyscraper.cpp:96:13: warning: 'ini' may be used uninitialized in this function [-Wmaybe-uninitialized]
   96 |     dijkstra(ini,n);
      |     ~~~~~~~~^~~~~~~
#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...