Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
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] = std::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 main()':
a.cc:49:24: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   49 |                 answer += mvCost[iGuest,jGuest];
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
      |                        |
      |                        int*
a.cc:50:37: error: lvalue required as decrement operand
   50 |                 mvCost[iGuest,jGuest]--;
      |                 ~~~~~~~~~~~~~~~~~~~~^
a.cc:51:27: error: 'iGuest1' was not declared in this scope; did you mean 'iGuest'?
   51 |                 if(mvCost[iGuest1,jGuest]+1 < mvCost[iGuest+1,jGuest]){
      |                           ^~~~~~~
      |                           iGuest
a.cc:52:44: error: too few arguments to function 'int ijToNum(int, int, int)'
   52 |                 subtrSeat.push_back(ijToNum(iGuest+1,jGuest));
      |                                     ~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:7:5: note: declared here
    7 | int ijToNum(int nLine, int i, int j){
      |     ^~~~~~~
a.cc:54:27: error: 'iGuest1' was not declared in this scope; did you mean 'iGuest'?
   54 |                 if(mvCost[iGuest1,jGuest]+1 < mvCost[iGuest-1,jGuest]){
      |                           ^~~~~~~
      |                           iGuest
a.cc:55:44: error: too few arguments to function 'int ijToNum(int, int, int)'
   55 |                 subtrSeat.push_back(ijToNum(iGuest-1,jGuest));
      |                                     ~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:7:5: note: declared here
    7 | int ijToNum(int nLine, int i, int j){
      |     ^~~~~~~
a.cc:57:27: error: 'iGuest1' was not declared in this scope; did you mean 'iGuest'?
   57 |                 if(mvCost[iGuest1,jGuest]+1 < mvCost[iGuest,jGuest+1]){
      |                           ^~~~~~~
      |                           iGuest
a.cc:58:44: error: too few arguments to function 'int ijToNum(int, int, int)'
   58 |                 subtrSeat.push_back(ijToNum(iGuest,jGuest+1));
      |                                     ~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:7:5: note: declared here
    7 | int ijToNum(int nLine, int i, int j){
      |     ^~~~~~~
a.cc:60:27: error: 'iGuest1' was not declared in this scope; did you mean 'iGuest'?
   60 |                 if(mvCost[iGuest1,jGuest]+1 < mvCost[iGuest+1,jGuest]){
      |                           ^~~~~~~
      |                           iGuest
a.cc:61:44: error: too few arguments to function 'int ijToNum(int, int, int)'
   61 |                 subtrSeat.push_back(ijToNum(iGuest,jGuest+1));
      |                                     ~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:7:5: note: declared here
    7 | int ijToNum(int nLine, int i, int j){
      |     ^~~~~~~