Language: C++

#include<bits/stdc++.h>
using namespace std;
int dis[502][502], N;
bool occ[502][502];
typedef pair<int, int>pi;
int dirx[]= {0, 1, 0, -1};
int diry[]= {1, 0, -1, 0};
void bfs(int x, int y)
{
    queue<pi>q;
    q.push({x, y});
    while(!q.empty())
    {
        x= q.front().first;
        y= q.front().second;
        q.pop();
        int z= dis[x][y]+occ[x][y];
        for(int i=0; i<4; i++)
        {
            int x1= x+dirx[i];
            int y1= y+diry[i];
            if(x1>=1 && x1<=N && y1>=1 && y1<=N && dis[x1][y1]>z)
            dis[x1][y1]= z, q.push({x1, y1});
        }
    }
    return;
}
int main()
{
    int x, y, z;
    scanf("%d", &N);
    for(int i=1; i<=N; i++)
    for(int j=1; j<=N; j++)
    dis[i][j]= min(min(i-1, N-i), min(j-1, N-j)), occ[i][j]= 1;
    int res= 0;
    for(int i=1; i<=N*N; i++)
    {
        scanf("%d", &z);
        x= (z+N-1)/N;
        y= z-(x-1)*N;
        res+= dis[x][y];
        occ[x][y]= 0;
        bfs(x, y);
    }
    printf("%d\n", res);
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
int dis[502][502], N;
bool occ[502][502];
typedef pair<int, int>pi;
int dirx[]= {0, 1, 0, -1};
int diry[]= {1, 0, -1, 0};
void bfs(int x, int y)
{
    queue<pi>q;
    q.push({x, y});
    while(!q.empty())
    {
        x= q.front().first;
        y= q.front().second;
        q.pop();
        int z= dis[x][y]+occ[x][y];
        for(int i=0; i<4; i++)
        {
            int x1= x+dirx[i];
            int y1= y+diry[i];
            if(x1>=1 && x1<=N && y1>=1 && y1<=N && dis[x1][y1]>z)
            dis[x1][y1]= z, q.push({x1, y1});
        }
    }
    return;
}
int main()
{
    int x, y, z;
    scanf("%d", &N);
    for(int i=1; i<=N; i++)
    for(int j=1; j<=N; j++)
    dis[i][j]= min(min(i-1, N-i), min(j-1, N-j)), occ[i][j]= 1;
    int res= 0;
    for(int i=1; i<=N*N; i++)
    {
        scanf("%d", &z);
        x= (z+N-1)/N;
        y= z-(x-1)*N;
        res+= dis[x][y];
        occ[x][y]= 0;
        bfs(x, y);
    }
    printf("%d\n", res);
    return 0;


Compiler output:
a.cc:50:5: error: redefinition of 'int dis [502][502]'
   50 | int dis[502][502], N;
      |     ^~~
a.cc:3:5: note: 'int dis [502][502]' previously declared here
    3 | int dis[502][502], N;
      |     ^~~
a.cc:50:20: error: redefinition of 'int N'
   50 | int dis[502][502], N;
      |                    ^
a.cc:3:20: note: 'int N' previously declared here
    3 | int dis[502][502], N;
      |                    ^
a.cc:51:6: error: redefinition of 'bool occ [502][502]'
   51 | bool occ[502][502];
      |      ^~~
a.cc:4:6: note: 'bool occ [502][502]' previously declared here
    4 | bool occ[502][502];
      |      ^~~
a.cc:53:5: error: redefinition of 'int dirx []'
   53 | int dirx[]= {0, 1, 0, -1};
      |     ^~~~
a.cc:6:5: note: 'int dirx [4]' previously defined here
    6 | int dirx[]= {0, 1, 0, -1};
      |     ^~~~
a.cc:54:5: error: redefinition of 'int diry []'
   54 | int diry[]= {1, 0, -1, 0};
      |     ^~~~
a.cc:7:5: note: 'int diry [4]' previously defined here
    7 | int diry[]= {1, 0, -1, 0};
      |     ^~~~
a.cc:55:6: error: redefinition of 'void bfs(int, int)'
   55 | void bfs(int x, int y)
      |      ^~~
a.cc:8:6: note: 'void bfs(int, int)' previously defined here
    8 | void bfs(int x, int y)
      |      ^~~
a.cc:75:5: error: redefinition of 'int main()'
   75 | int main()
      |     ^~~~
a.cc:28:5: note: 'int main()' previously defined here
   28 | int main()
      |     ^~~~
a.cc: In function 'int main()':
a.cc:93:14: error: expected '}' at end of input
   93 |     return 0;
      |              ^
a.cc:76:1: note: to match this '{'
   76 | {
      | ^