Created
February 12, 2018 08:58
-
-
Save deque-blog/e434055fec13c84ff0dd66093813f782 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Coord = std::pair<int, int>; | |
using Matrix = std::vector<vector<int>>; | |
int read_int() | |
{ | |
int n; | |
std::cin >> n; | |
return n; | |
} | |
Matrix read_matrix() | |
{ | |
Matrix m; | |
int n = read_int(); | |
for (int i = 0; i < 2 * n; ++i) | |
{ | |
m.push_back({}); | |
for (int j = 0; j < 2 * n; ++j) | |
{ | |
m.back().push_back(read_int()); | |
} | |
} | |
return m; | |
} | |
std::vector<int> symetric_values(Matrix const& m, int n, Coord const& c) | |
{ | |
int i = c.first; | |
int j = c.second; | |
int max = 2 * n - 1; | |
return { m[i][j] | |
, m[max-i][j] | |
, m[i][max-j] | |
, m[max-i][max-j] }; | |
} | |
int best_quadrant(Matrix const& m) | |
{ | |
int sum = 0; | |
int n = m.size() / 2; | |
for (int i = 0; i < n; ++i) | |
{ | |
for (int j = 0; j < n; ++j) | |
{ | |
auto flips = symetric_values(m, n, {i, j}); | |
sum += *std::max_element(flips.begin(), flips.end()); | |
} | |
} | |
return sum; | |
} | |
int main() | |
{ | |
int n = read_int(); | |
for (int i = 0; i < n; ++i) | |
{ | |
Matrix m = read_matrix(); | |
std::cout << best_quadrant(m) << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment