Created
February 12, 2018 09:02
-
-
Save deque-blog/9bb2bba56df6e6ae76c5e1c5ca499138 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 i; | |
std::cin >> i; | |
return i; | |
} | |
std::vector<int> read_line(int n) | |
{ | |
std::vector<int> line; | |
std::generate_n(std::back_inserter(line), 2 * n, read_int); | |
return line; | |
} | |
Matrix read_matrix() | |
{ | |
Matrix m; | |
int n = read_int(); | |
std::generate_n(std::back_inserter(m), 2 * n, [=]{ return read_line(n); }); | |
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 n = m.size() / 2; | |
int sum = 0; | |
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(); | |
std::generate_n(std::ostream_iterator<int>(std::cout, "\n"), n, []{ | |
return best_quadrant(read_matrix()); | |
}); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment