結果
問題 | 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: trueclass Integerdef pyramidw = 2 * self - 1c = self - 1a = Array.new(w)a[0] = 1(1..c).each do |i|a[i] = a[i - 1] + 1end(c + 1..w - 1).each do |i|a[i] = a[i - 1] - 1endaendendclass Arraydef resize(other)some = selfother = otherif some.size < other.sizesome.fill(some.size, other.size - some.size) { 0 }elseother.fill(other.size, some.size - other.size) { 0 }end[some, other]endenddef solves = A.sumn = Integer.sqrt(s)pyramid = n.pyramidoriginal, pyramid = A.resize(pyramid)original.zip(pyramid).map { |o, p| o - p }.filter { _1 > 0 }.sumendN = gets.to_iA = gets.split.map(&:to_i)puts solve