結果

問題 No.77 レンガのピラミッド
ユーザー Tsuneo YoshiokaTsuneo Yoshioka
提出日時 2014-11-26 00:22:58
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 698 bytes
コンパイル時間 498 ms
コンパイル使用メモリ 11,312 KB
実行使用メモリ 15,348 KB
最終ジャッジ日時 2023-09-01 22:02:43
合計ジャッジ時間 3,938 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
15,120 KB
testcase_01 AC 74 ms
15,032 KB
testcase_02 AC 74 ms
15,184 KB
testcase_03 AC 77 ms
15,300 KB
testcase_04 WA -
testcase_05 AC 77 ms
15,244 KB
testcase_06 WA -
testcase_07 AC 77 ms
15,064 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 80 ms
15,004 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# Here your code !
# 1 + 3 + 5 + ... = N * (1 + (2N-1))/2 = N * N

N = gets.to_i
A = gets.split.map(&:to_i)
sum = A.inject(&:+)
level = Math.sqrt(sum).floor
mintotal = 1000000
#puts "level=#{level}"
(0...N).each{|i|
    total = 0
    #puts "i=#{i}"
    # (-(level-1)..(level-1)).each{|j|
    (0...N).each{|j|
        h = A[j]
        base = 0 
        if level >= (i-j).abs
             base = level - (i-j).abs 
        end
        if h > base then
            diff = (h - base).abs
            total += diff
        end
        #puts "i=#{i}, j=#{j}, h=#{h}, base=#{base}, diff=#{diff}, total=#{total}"
    }
    mintotal = [mintotal, total].min
}
puts mintotal



0