Submission #410219

#TimeUsernameProblemLanguageResultExecution timeMemory
410219jeqchoJakarta Skyscrapers (APIO15_skyscraper)C++17
22 / 100
4 ms1484 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<pair<int,int>> vpi; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define pb push_back #define rsz resize #define sz(x) int(x.size()) #define all(x) begin(x), end(x) #define fi first #define se second struct triple { int a,b,c; }; bool operator<(const triple &x, const triple &y) { return x.a<y.a; } int const N=3e4; int const sN=170; int d[N][sN]; int const INF=1e9; bitset<sN> vis[N]; priority_queue<triple> q; vi doges[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,m; cin>>n>>m; int b0,b1; F0R(i,m) { int bi,pi; cin>>bi>>pi; if(i==0)b0=bi; else if(i==1)b1=bi; doges[bi].pb(pi); } F0R(i,n) { fill(d[i],d[i]+sN,INF); } d[b0][0]=0; q.push({0,b0,0}); while(!q.empty()) { int pos = q.top().b; int pw = q.top().c; q.pop(); if(vis[pos][pw])continue; vis[pos][pw]=1; vector<triple>adj; if(pw!=0) { adj.pb({pos,0,0}); if(pw>=sN) { int nxt=pos+pw; int cnt=1; while(nxt<n) { adj.pb({pos,0,cnt}); ++cnt; nxt+=pw; } nxt=pos-pw; cnt=1; while(nxt>=0) { adj.pb({pos,0,cnt}); ++cnt; nxt-=pw; } } else { int nxt=pos+pw; if(nxt<n) { adj.pb({nxt,pw,1}); } nxt=pos-pw; if(nxt>=0) { adj.pb({nxt,pw,1}); } } } else { trav(pwr,doges[pos]) { adj.pb({pos,pwr,0}); } } trav(e,adj) { int cand = d[pos][pw]+e.c; if(cand<d[e.a][e.b]) { d[e.a][e.b]=cand; q.push({-cand,e.a,e.b}); } } } if(d[b1][0]==INF)cout<<-1<<'\n'; else cout<<d[b1][0]<<'\n'; return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:121:12: warning: 'b1' may be used uninitialized in this function [-Wmaybe-uninitialized]
  121 |  if(d[b1][0]==INF)cout<<-1<<'\n';
      |     ~~~~~~~^
skyscraper.cpp:59:8: warning: 'b0' may be used uninitialized in this function [-Wmaybe-uninitialized]
   59 |  q.push({0,b0,0});
      |  ~~~~~~^~~~~~~~~~
#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...