// original: // https://yukicoder.me/submissions/8485 #pragma GCC optimize("Ofast") #pragma GCC target("avx2") //char*mmap(); char rbuf[24*1024]; #define RD(v) int v=0;{int c;while(c=*rp++-48,c>=0)v=v*10+c;} #define RDL(v) long v=0;{int c;while(c=*rp++-48,c>=0)v=v*10+c;} #define REP(i,a,b) for(i=a;ic||a>b&&b= h || nx<0 || nx>= w) continue; if(!isK(k,nk,rp[ny*w+nx<<1])) continue; if(dist[nk][ny][nx] > 0) continue; dist[nk][ny][nx] = dist[k][y][x] + 1; *qw++ = nk; *qw++ = ny; *qw++ = nx; } } printf("%d",z); }