Language: C++

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int ijToNum(int nLine, int i, int j){
  	int seatNum = j*nLine+i+1;
  	return seatNum;
}

int numToJ(int nLine, int seatNum){
 	int jGuest = ( (seatNum-1) / nLine);// [0,N-1]
  	return jGuest;
}

int numToI(int nLine, int seatNum){
 	int yGuest = numToJ(nLine, seatNum) + 1;// [1,N]
    int xGUest = seatNum - nLine*(yGuest-1);// [1,N]
  	return xGuest-1;
}

int main(){
  	int answer =0;
  	
	int nLine;
  	cin >> nLine;
    int mvCost[nLine][nLine];
  	for(int i=0;i<nLine;i++){
    	for(int j=0;j<nLine;j++){
          	mvCost[i][j] = min({i,j,nLine-1-i,nLine-1-j});
        }
    }
  	
  	int nGuest = nLine*nLine;
  	int seatNum[nGuest];
  	for(int iGuest=0;iGuest<nGuest;iGuest++){
  		cin >> seatNum[iGuest];
    }
  	
  	std::vector<int> subtrSeat;
  	for(int iGuest=0;iGuest<nGuest;iGuest++){
      	subtrSeat.push_back(seatNum[iGuest]);
      	
      	while( (int)subtrSeat.size() > 0){
	      	int iGuest = numToI(nLine, subtrSeat[0]);
    	  	int jGuest = numToJ(nLine, subtrSeat[0]);
          	
          	answer += mvCost[iGuest,jGuest];
          	mvCost[iGuest,jGuest]--;
          	if(mvCost[iGuest1,jGuest]+1 < mvCost[iGuest+1,jGuest]){
              	subtrSeat.push_back(ijToNum(iGuest+1,jGuest));
            }
          	if(mvCost[iGuest1,jGuest]+1 < mvCost[iGuest-1,jGuest]){
              	subtrSeat.push_back(ijToNum(iGuest-1,jGuest));
            }
          	if(mvCost[iGuest1,jGuest]+1 < mvCost[iGuest,jGuest+1]){
              	subtrSeat.push_back(ijToNum(iGuest,jGuest+1));
            }
          	if(mvCost[iGuest1,jGuest]+1 < mvCost[iGuest+1,jGuest]){
              	subtrSeat.push_back(ijToNum(iGuest,jGuest+1));
            }
      		subtrSeat.erase(subtrSeat.begin());
        }
    }
  	
  	cout << answer;
}


Compiler output:
a.cc: In function 'int numToI(int, int)':
a.cc:19:16: error: 'xGuest' was not declared in this scope; did you mean 'xGUest'?
   19 |         return xGuest-1;
      |                ^~~~~~
      |                xGUest
a.cc: In function 'int main()':
a.cc:30:35: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   30 |                 mvCost[i][j] = min({i,j,nLine-1-i,nLine-1-j});
      |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
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:   candidate expects 2 arguments, 1 provided
/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, 1 provided
a.cc:48:24: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   48 |                 answer += mvCost[iGuest,jGuest];
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
      |                        |
      |                        int*
a.cc:49:37: error: lvalue required as decrement operand
   49 |                 mvCost[iGuest,jGuest]--;
      |                 ~~~~~~~~~~~~~~~~~~~~^
a.cc:50:27: error: 'iGuest1' was not declared in this scope; did you mean 'iGuest'?
   50 |                 if(mvCost[iGuest1,jGuest]+1 < mvCost[iGuest+1,jGuest]){
      |                           ^~~~~~~
      |                           iGuest
a.cc:51:44: error: too few arguments to function 'int ijToNum(int, int, int)'
   51 |                 subtrSeat.push_back(ijToNum(iGuest+1,jGuest));
      |                                     ~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:6:5: note: declared here
    6 | int ijToNum(int nLine, int i, int j){
      |     ^~~~~~~
a.cc:53:27: error: 'iGuest1' was not declared in this scope; did you mean 'iGuest'?
   53 |                 if(mvCost[iGuest1,jGuest]+1 < mvCost[iGuest-1,jGuest]){
      |                           ^~~~~~~
      |                           iGuest
a.cc:54:44: error: too few arguments to function 'int ijToNum(int, int, int)'
   54 |                 subtrSeat.push_back(ijToNum(iGuest-1,jGuest));
      |                                     ~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:6:5: note: declared here
    6 | int ijToNum(int nLine, int i, int j){
      |     ^~~~~~~
a.cc:56:27: error: 'iGuest1' was not declared in this scope; did you mean 'iGuest'?
   56 |                 if(mvCost[iGuest1,jGuest]+1 < mvCost[iGuest,jGuest+1]){
      |                           ^~~~~~~
      |                           iGuest
a.cc:57:44: error: too few arguments to function 'int ijToNum(int, int, int)'
   57 |                 subtrSeat.push_back(ijToNum(iGuest,jGuest+1));
      |                                     ~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:6:5: note: declared here
    6 | int ijToNum(int nLine, int i, int j){
      |     ^~~~~~~
a.cc:59:27: error: 'iGuest1' was not declared in this scope; did you mean 'iGuest'?
   59 |                 if(mvCost[iGuest1,jGuest]+1 < mvCost[iGuest+1,jGuest]){
      |                           ^~~~~~~
      |                           iGuest
a.cc:60:44: error: too few arguments to function 'int ijToNum(int, int, int)'
   60 |                 subtrSeat.push_back(ijToNum(iGuest,jGuest+1));
      |                                     ~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:6:5: note: declared here
    6 | int ijToNum(int nLine, int i, int j){
      |     ^~~~~~~