結果

問題 No.77 レンガのピラミッド
ユーザー Tsuneo YoshiokaTsuneo Yoshioka
提出日時 2014-11-26 00:35:03
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 821 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 11,380 KB
実行使用メモリ 15,416 KB
最終ジャッジ日時 2023-09-01 22:05:46
合計ジャッジ時間 3,290 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,252 KB
testcase_01 AC 79 ms
15,144 KB
testcase_02 AC 80 ms
15,260 KB
testcase_03 AC 80 ms
15,164 KB
testcase_04 AC 80 ms
15,092 KB
testcase_05 AC 81 ms
15,152 KB
testcase_06 WA -
testcase_07 AC 82 ms
15,292 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 81 ms
15,160 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
level = [level,(N+1)/2].min
mintotal = 1000000
#puts "sum=#{sum}, level=#{level}"
(0+(level-1)...N-(level-1)).each{|i|
    total = 0
    #puts "i=#{i}"
    # (-(level-1)..(level-1)).each{|j|
    (0...N).each{|j|
        h = 0
        if j>=0 && j< N then
            h = A[j]
        end
        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