Language: C++

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
typedef long long ll;
#define mp make_pair

const ll N = 100005;

ll dx[4] = {0,0,1,-1};
ll dy[4] = {1,-1,0,0};

bool check(ll x,ll y, ll n, ll m){
    return x>=0 && y>=0 && x<n && y<m;
}
int main(){
    ll n;
    cin >> n;
    ll p = n * n;
    ll P[p];
    for(int i=0;i<p;i++){
		cin >> P[i];	
	}
    ll D[n][n];
    ll vis[n][n];
    for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
	    	ll a = min(i,n-i-1);
	    	ll b = min(j,n-j-1);
	    	D[i][j]=min(a,b);
	    	vis[i][j]=1;
    	}
    }
    ll ans=0;
    for(int i=0;i<p;i++){
    	ll r = P[i];
    	ll x = (r-1)/n;
    	ll y = (r-1)%n;
    	queue<pll> q;
    	q.push({x,y});
    	ans += D[x][y];
    	vis[x][y] = 0;
    	while(!q.empty()){
    		pll r = q.front();
    		q.pop();
    		for(int j=0;j<4;j++){
    			ll nx = r.ft+dx[j];
    			ll ny = r.sd+dy[j];
    			if(check(nx,ny,n,n) and D[nx][ny] > D[r.ft][r.sd] + vis[r.ft][r.sd]){
    				q.push({nx, ny});
    				D[nx][ny] = D[r.ft][r.sd] + vis[r.ft][r.sd];
    			}
    		}	
    	}
    }
    
    cout<<ans<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:48:27: error: no matching function for call to 'min(int&, ll)'
   48 |                 ll a = min(i,n-i-1);
      |                        ~~~^~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:48:27: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   48 |                 ll a = min(i,n-i-1);
      |                        ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:7:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:48:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   48 |                 ll a = min(i,n-i-1);
      |                        ~~~^~~~~~~~~
a.cc:49:27: error: no matching function for call to 'min(int&, ll)'
   49 |                 ll b = min(j,n-j-1);
      |                        ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:49:27: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   49 |                 ll b = min(j,n-j-1);
      |                        ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:49:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   49 |                 ll b = min(j,n-j-1);
      |                        ~~~^~~~~~~~~
a.cc:59:15: error: 'pll' was not declared in this scope; did you mean 'll'?
   59 |         queue<pll> q;
      |               ^~~
      |               ll
a.cc:59:18: error: template argument 1 is invalid
   59 |         queue<pll> q;
      |                  ^
a.cc:59:18: error: template argument 2 is invalid
a.cc:60:11: error: request for member 'push' in 'q', which is of non-class type 'int'
   60 |         q.push({x,y});
      |           ^~~~
a.cc:63:18: error: request for member 'empty' in 'q', which is of non-class type 'int'
   63 |         while(!q.empty()){
      |                  ^~~~~
a.cc:64:20: error: expected ';' before 'r'
   64 |                 pll r = q.front();
      |                    ^~
      |                    ;
a.cc:65:19: error: request for member 'pop' in 'q', which is of non-class type 'int'
   65 |                 q.pop();
      |                   ^~~
a.cc:67:35: error: request for member 'ft' in 'r', which is of non-class type 'll' {aka 'long long int'}
   67 |                         ll nx = r.ft+dx[j];
      |                                   ^~
a.cc:68:35: error: request for member 'sd' in 'r', which is of non-class type 'll' {aka 'long long int'}
   68 |                         ll ny = r.sd+dy[j];
      |                                   ^~
a.cc:69:65: error: request for member 'ft' in 'r', which is of non-class type 'll' {aka 'long long int'}
   69 |                         if(check(nx,ny,n,n) and D[nx][ny] > D[r.ft][r.sd] + vis[r.ft][r.sd]){
      |                                                                 ^~
a.cc:69:71: error: request for member 'sd' in 'r', which is of non-class type 'll' {aka 'long long int'}
   69 |                         if(check(nx,ny,n,n) and D[nx][ny] > D[r.ft][r.sd] + vis[r.ft][r.sd]){
      |                                                                       ^~
a.cc:69:83: error: request for member 'ft' in 'r', which is of non-class type 'll' {aka 'long long int'}
   69 |                         if(check(nx,ny,n,n) and D[nx][ny] > D[r.ft][r.sd] + vis[r.ft][r.sd]){
      |                                                                                   ^~
a.cc:69:89: error: request for member 'sd' in 'r', which is of non-class type 'll' {aka 'long long int'}
   69 |                         if(check(nx,ny,n,n) and D[nx][ny] > D[r.ft][r.sd] + vis[r.ft][r.sd]){
      |                                                                                         ^~
a.cc:70:35: error: request for member 'push' in 'q', which is of non-class type 'int'
   70 |                                 q.push({nx, ny});
      |                                   ^~~~
a.cc:71:49: error: request for member 'ft' in 'r', which is of non-class type 'll' {aka 'long long int'}
   71 |                                 D[nx][ny] = D[r.ft][r.sd] + vis[r.ft][r.sd];
      |                                                 ^~
a.cc:71:55: error: request for member 'sd' in 'r', which is of non-class type 'll' {aka 'long long int'}
   71 |                                 D[nx][ny] = D[r.ft][r.sd] + vis[r.ft][r.sd];
      |                                                       ^~
a.cc:71:67: error: request for member 'ft' in 'r', which is of non-class type 'll' {aka 'long long int'}
   71 |                                 D[nx][ny] = D[r.ft][r.sd] + vis[r.ft][r.sd];
      |                                                                   ^~
a.cc:71:73: error: request for member 'sd' in 'r', which is of non-class type 'll' {aka 'long long int'}
   71 |                                 D[nx][ny] = D[r.ft][r.sd] + vis[r.ft][r.sd];
      |                                                                         ^~