Skip to content

Created Solution.php #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Solution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
function solve() {
$T = intval(readline());
for ($t = 0; $t < $T; $t++) {
$n = intval(readline());
$a = [];
for ($i = 0; $i < 2 * $n; $i++) {
$a[] = array_map('intval', explode(' ', readline()));
}
$ret = 0;
for ($i = 0; $i < $n; $i++) {
for ($j = 0; $j < $n; $j++) {
$max = max(
$a[$i][$j],
$a[2 * $n - 1 - $i][$j],
$a[2 * $n - 1 - $i][2 * $n - 1 - $j],
$a[$i][2 * $n - 1 - $j]
);
$ret += $max;
}
}
echo $ret . PHP_EOL;
}
}

solve();
?>
22 changes: 22 additions & 0 deletions Solution.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def solve
t = gets.to_i
t.times do
n = gets.to_i
a = Array.new(2 * n) { gets.split.map(&:to_i) }
ret = 0
n.times do |i|
n.times do |j|
max_val = [
a[i][j],
a[2 * n - 1 - i][j],
a[2 * n - 1 - i][2 * n - 1 - j],
a[i][2 * n - 1 - j]
].max
ret += max_val
end
end
puts ret
end
end

solve