結果
| 問題 |
No.77 レンガのピラミッド
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2015-04-02 22:14:17 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 92 ms / 5,000 ms |
| コード長 | 823 bytes |
| コンパイル時間 | 171 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 12,416 KB |
| 最終ジャッジ日時 | 2024-07-03 23:36:43 |
| 合計ジャッジ時間 | 3,198 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 20 |
コンパイルメッセージ
Main.rb:3: warning: assigned but unused variable - n Syntax OK
ソースコード
class Yukicoder
def initialize
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)
min_move_count = Float::INFINITY
1.upto(100) do |num|
array = pyramid_array(num)
move_count = 0
from_count = 0
to_count = 0
break if a.inject(:+) < array.inject(:+)
a.each_with_index do |num, index|
count = num - (array[index] || 0)
if count < 0
from_count += count
else
to_count += count
end
end
move_count = [from_count, to_count].min + [from_count, to_count].max - [from_count, to_count].min
min_move_count = [min_move_count, move_count].min
end
puts min_move_count
end
def pyramid_array(num)
[1] if num == 1
[*(1..num-1)] + [num] + [*(1..num-1)].reverse
end
end
Yukicoder.new
siman