#include #include #include #include #include #include using namespace std; typedef typename std::array my_array_t; typedef typename std::array my_matrix_t; int get_cost( my_matrix_t &matrix, my_matrix_t &magic ){ int cost = 0; for(int i = 0; i &all_magics ){ vector costs; for( int i = 0; i < all_magics.size(); ++i ){ costs.push_back( get_cost( matrix, all_magics[i]) ); } return *std::min_element(costs.begin(), costs.end()); } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ my_matrix_t matrix; array all_magics {8,1,6,3,5,7,4,9,2, 6,1,8,7,5,3,2,9,4, 4,3,8,9,5,1,2,7,6, 2,7,6,9,5,1,4,3,8, 2,9,4,7,5,3,6,1,8, 4,9,2,3,5,7,8,1,6, 6,7,2,1,5,9,8,3,4, 8,3,4,1,5,9,6,7,2}; for( int i = 0; i < matrix.size(); ++i){ for( int j = 0; j < matrix[i].size(); ++j){ std::cin >> matrix[i][j]; } } std::cout << get_min_cost( matrix, all_magics ); return 0; }