Submission #780500

#TimeUsernameProblemLanguageResultExecution timeMemory
780500mrwangJakarta Skyscrapers (APIO15_skyscraper)C++14
22 / 100
550 ms262144 KiB
#include<bits/stdc++.h> #define TASKNAME "codeforce" #define pb push_back #define pli pair<ll,ll> #define fi first #define se second #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); using namespace std; using ll=long long; const ll maxN=3e4+100; const ll inf=1e18; const ll mod=1e9+7; ll n; ll dis[maxN]; priority_queue<pli,vector<pli>,greater<pli>>pq; vector<pli>g[maxN]; void dij(ll s) { for(int i=0;i<n;i++) dis[i]=inf; dis[s]=0; pq.push({dis[s],s}); while(!pq.empty()) { ll u=pq.top().se; ll d=pq.top().fi; pq.pop(); if(d>dis[u]) continue; for(auto vv:g[u]) { int v=vv.fi; int w=vv.se; if(dis[v]>dis[u]+w) { dis[v]=dis[u]+w; pq.push({dis[v],v}); } } } } ll m; ll p[maxN],b[maxN]; const ll block=175; vector<ll>vec[block+2][block+2]; void solve() { cin >> n >> m; for(int i=1;i<=m;i++) { cin >> b[i] >> p[i]; } for(int i=1;i<=m;i++) { if(p[i]>block) { for(int j=b[i]-p[i];j>=0;j-=p[i]) { g[i].pb({j,(i-j)/p[i]}); } for(int j=b[i]+p[i];j<n;j+=p[i]) { g[i].pb({j,(j-i)/p[i]}); } } else { vec[p[i]][b[i]%p[i]].pb(b[i]); } } for(int i=1;i<=block;i++) { for(int j=0;j<i;j++) { sort(vec[i][j].begin(),vec[i][j].end()); for(int k=0;k<vec[i][j].size();k++) { ll pos=vec[i][j][k]; ll pos2=k>0?vec[i][j][k-1]:0; for(int q=pos-i;q>=pos2;q-=i) { g[pos].pb({q,(pos-q)/i}); } pos2=(k+1<vec[i][j].size())?vec[i][j][k+1]:n-1; for(int q=pos+i;q<=pos2;q+=i) { g[pos].pb({q,(q-pos)/i}); } } } } dij(b[1]); if(dis[b[2]]==inf) cout << -1<<'\n'; else cout << dis[b[2]]; } int main() { fastio //freopen(TASKNAME".INP","r",stdin); //freopen(TASKNAME".OUT","w",stdout); solve(); }

Compilation message (stderr)

skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:74:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             for(int k=0;k<vec[i][j].size();k++)
      |                         ~^~~~~~~~~~~~~~~~~
skyscraper.cpp:82:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |                 pos2=(k+1<vec[i][j].size())?vec[i][j][k+1]:n-1;
      |                       ~~~^~~~~~~~~~~~~~~~~
#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...