#include #define N 5001 using namespace std; int nGuard; int nInc; struct Point{ int x; int y; }; int playField[N][N]; //Point guards[100000]; //Point incidents[300000]; int first; int last; Point queue[N*N]; void expand(const Point &where, int time) { if (where.x < 0 || where.x >= N) return; if (where.y < 0 || where.y >= N) return; if (playField[where.x][where.y] == -1) { playField[where.x][where.y] = time; queue[last++] = where; } } int main() { scanf("%d %d", &nGuard, &nInc); for (int y = 0; y first ) { Point cur = queue[first++]; int time = playField[cur.x][cur.y]; expand(Point{cur.x+1, cur.y}, time+1); expand(Point{cur.x-1, cur.y}, time+1); expand(Point{cur.x, cur.y+1}, time+1); expand(Point{cur.x, cur.y-1}, time+1); expand(Point{cur.x+1, cur.y+1}, time+1); expand(Point{cur.x-1, cur.y-1}, time+1); expand(Point{cur.x-1, cur.y+1}, time+1); expand(Point{cur.x+1, cur.y-1}, time+1); } for (int i = 0; i