Language: C++

#include <iostream>

bool is_complete(int*);

int solve(int *, int);
void rot(int*, int);

int min(int, int, int, int);
void swap(int&, int&);

int main(){
	int N;
	int **p;
	std::cin >> N;
	p = new int*[N];
	for(int i=0; i<N; i++){
		p[i] = new int[30];
		for(int j=0; j<30; j++)
			std::cin >> p[i][j];
	}
	for(int i=0; i<N; i++)
		std::cout << min(rot(p[i], 1, 0), rot(p[i], 2, 0), rot(p[i], 3, 0), rot(p[i], 4, 0)) << std::endl;
}

bool is_complete(int* p){
	int cmp=p[0];
	for(int i=0; i<30; i++){
		if(i == 9)
			cmp = p[9];
		else if(i == 12)
			cmp = p[12];
		else if(i == 15)
			cmp = p[15];
		else if(i == 18)
			cmp = p[18];
		else if(i == 21)
			cmp = p[21];
		else if(cmp != p[i])
			return false;
	}
	return true;
}

int solve(int *p, int cnt){
	if(cnt == 9 || is_complete(p))
		return cnt;
	int **pp = new int*[4];
	for(int i=0; i<4; i++){
		pp[i] = new int[30];
		for(int j=0; j<30; j++)
			pp[i][j] = p[j];
	}
	delete[] p;
	for(int dir=1; dir<=4; dir++){
		rot(pp[dir-1], dir);
		if(is_complete(pp))
			return cnt;
	}
}

void rot(int* p, int dir){
	if(dir == 1){
		swap(p[6], p[21]);
		swap(p[7], p[22]);
		swap(p[8], p[23]);
		swap(p[9], p[11]);
		swap(p[12], p[17]);
	}else if(dir == 2){
		swap(p[0], p[27]);
		swap(p[1], p[28]);
		swap(p[2], p[29]);
		swap(p[18], p[20]);
		swap(p[14], p[15]);
	}else if(dir == 3){
		swap(p[0], p[23]);
		swap(p[3], p[26]);
		swap(p[6], p[29]);
		swap(p[15], p[17]);
		swap(p[9], p[20]);
	}else{
		swap(p[2], p[21]);
		swap(p[5], p[24]);
		swap(p[8], p[27]);
		swap(p[12], p[14]);
		swap(p[11], p[18]);
	}
}

int min(int a, int b, int c, int d){
	int ans = a;
	if(ans > b)
		ans = b;
	if(ans > c)
		ans = c;
	if(ans > d)
		ans = d;
	return ans;
}

void swap(int& a, int& b){
	int tmp = a;
	a = b;
	b = tmp;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:37: error: too many arguments to function 'void rot(int*, int)'
   22 |                 std::cout << min(rot(p[i], 1, 0), rot(p[i], 2, 0), rot(p[i], 3, 0), rot(p[i], 4, 0)) << std::endl;
      |                                  ~~~^~~~~~~~~~~~
a.cc:6:6: note: declared here
    6 | void rot(int*, int);
      |      ^~~
a.cc:22:54: error: too many arguments to function 'void rot(int*, int)'
   22 |                 std::cout << min(rot(p[i], 1, 0), rot(p[i], 2, 0), rot(p[i], 3, 0), rot(p[i], 4, 0)) << std::endl;
      |                                                   ~~~^~~~~~~~~~~~
a.cc:6:6: note: declared here
    6 | void rot(int*, int);
      |      ^~~
a.cc:22:71: error: too many arguments to function 'void rot(int*, int)'
   22 |                 std::cout << min(rot(p[i], 1, 0), rot(p[i], 2, 0), rot(p[i], 3, 0), rot(p[i], 4, 0)) << std::endl;
      |                                                                    ~~~^~~~~~~~~~~~
a.cc:6:6: note: declared here
    6 | void rot(int*, int);
      |      ^~~
a.cc:22:88: error: too many arguments to function 'void rot(int*, int)'
   22 |                 std::cout << min(rot(p[i], 1, 0), rot(p[i], 2, 0), rot(p[i], 3, 0), rot(p[i], 4, 0)) << std::endl;
      |                                                                                     ~~~^~~~~~~~~~~~
a.cc:6:6: note: declared here
    6 | void rot(int*, int);
      |      ^~~
a.cc:22:37: error: invalid use of void expression
   22 |                 std::cout << min(rot(p[i], 1, 0), rot(p[i], 2, 0), rot(p[i], 3, 0), rot(p[i], 4, 0)) << std::endl;
      |                                  ~~~^~~~~~~~~~~~
a.cc: In function 'int solve(int*, int)':
a.cc:56:32: error: cannot convert 'int**' to 'int*'
   56 |                 if(is_complete(pp))
      |                                ^~
      |                                |
      |                                int**
a.cc:25:23: note:   initializing argument 1 of 'bool is_complete(int*)'
   25 | bool is_complete(int* p){
      |                  ~~~~~^
a.cc:59:1: warning: control reaches end of non-void function [-Wreturn-type]
   59 | }
      | ^