vector<vector<int> > Solution::solve(int A, vector<vector<int>> &B) { int n = B.size(), m = B[0].size(); vector<vector<int>> res = B; queue<array<int,5>> q; for(int i = 0; i < B.size(); i++) { for(int j = 0; j < B[0].size(); j++) { q.push({B[i][j], i, j, i, j}); } } int dy[4]{-1,0,1,0}, dx[4]{0,1,0,-1}; while(q.size()) { auto [v,y,x,oy,ox] = q.front(); q.pop(); for(int i = 0; i < 4; i++) { int ny = y + dy[i], nx = x + dx[i]; if(0 <= ny and ny < n and0 <= nx and nx < m and res[ny][nx] < v andabs(ny-oy) + abs(nx - ox) <= A) { res[ny][nx] = v; q.push({v,ny,nx,oy,ox}); } } } return res; }