結果
| 問題 |
No.77 レンガのピラミッド
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-13 11:02:21 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 91 ms / 5,000 ms |
| コード長 | 761 bytes |
| コンパイル時間 | 56 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 12,288 KB |
| 最終ジャッジ日時 | 2024-11-07 06:16:47 |
| 合計ジャッジ時間 | 3,291 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 20 |
コンパイルメッセージ
Syntax OK
ソースコード
# frozen_string_literal: true
class Integer
def pyramid
w = 2 * self - 1
c = self - 1
a = Array.new(w)
a[0] = 1
(1..c).each do |i|
a[i] = a[i - 1] + 1
end
(c + 1..w - 1).each do |i|
a[i] = a[i - 1] - 1
end
a
end
end
class Array
def resize(other)
some = self
other = other
if some.size < other.size
some.fill(some.size, other.size - some.size) { 0 }
else
other.fill(other.size, some.size - other.size) { 0 }
end
[some, other]
end
end
def solve
s = A.sum
n = Integer.sqrt(s)
pyramid = n.pyramid
original, pyramid = A.resize(pyramid)
original.zip(pyramid).map { |o, p| o - p }.filter { _1 > 0 }.sum
end
N = gets.to_i
A = gets.split.map(&:to_i)
puts solve