Descrption
Have \ (m\) only Doge, each doge can only go to \ (b_i+kp_i,k\in z\), ask No. 0 doge to pass the information to 1th number doge the minimum number of jump steps. \ (n\leqslant 3\times 10^4\)
Solution
Chunking.
Divide \ (p\) into two parts that are greater than \ (\sqrt n\) and less than equals \ (\sqrt n\), and then less than the part can be violent to build a graph and then connect to the edge, greater than the part directly connected to all the locations can be reached.
Complexity \ (O (n\sqrt n) \).
Ps:uoj on the extra Text ...
In fact, the complexity of the time is no problem ... Just a bit of card memory ...
Code
/************************************************************** problem:4070 User:beiyu language:c++ Result : Accepted time:8152 ms memory:175408 kb****************************************************************/#include & Lt;bits/stdc++.h>using namespace Std; #define UOR (I,J,K) for (int i=j;i<= (int.) k;i++) #define UEP (I,J,K) for (int i=j;i< (int) k;i++) inline int in (int x=0, Char S=getchar ()) {while (s> ' 9 ' | | s< ' 0 ') S=getchar (); while (s>= ' 0 ' &&s<= ' 9 ') x=x*10+s-' 0 ', S=getchar (); return x; } const int N = 30001;const int B = 86;const int NN = n*b+n;const int M = n*b*5;const int oo = 0x3f3f3f3f; int n,m,ss,tt,pe;int to[m],ww[m];int nxt[m],hd[nn];int d[nn];bool B[nn]; int get_id (int x,int y) {return x*n+y;} void Addedge (int u,int v,int W) {nxt[++pe]=hd[u],to[pe]=v,ww[pe]=w,hd[u]=pe;} int SPFA (int s,int t) {memset (d,0x3f,s Izeof (d)); Queue<int> Q;q.push (s); D[s]=0,b[s]=1; for (int x;! Q.empty ();) {X=q.front (), Q.pop (), b[x]=0; for (int i=hd[x];i;i=nxt[i]) {int v=to[i],w=ww[i]; if (D[x]+w<d[v]) {d[v]=d[x]+w; if (!b[v]) Q.push (v), b[v]=1; }}}return d[t]==oo?-1:d[t];} /*void out () {for (int i=0;i<= (b+1) *n+n-1;i++) {cout<<i<< "--"; UEP (J,0,g[i].size ()) cout<<edge[g[i][j]].to<< ""; cout<<endl; }}*/int Main () {//cout<<sizeof (to) *4/1024.0/1024.0<<endl; N=in (), M=in (); UEP (i,0,m) {int b=in (), P=in (); if (i==0) ss=b; if (i==1) tt=b; if (p>b) {for (int j=1;j*p<n;j++) {if (b+j*p<n) Addedge (B,B+J*P,J); if (b-j*p>=0) Addedge (B,B-J*P,J); }} else {Addedge (b,get_id (p,b), 0); }} for (int i=1;i<=b;i++) for (int j=0;j<i;j++) for (int k=j+i;k<n;k+=i) Addedge (get_id (i,k), get_id (I, K-i), 1), Addedge (get_id (i,k-i), get_id (i,k), 1); for (iNT i=1;i<=b;i++) for (int. j=0;j<i;j++) for (int k=j;k<n;k+=i) Addedge (get_id (i,k), k,0); Out (); printf ("%d\n", SPFA (SS,TT)); return 0;}
Bzoj 4070: [Apio2015] The skyscrapers of Jakarta