結果

問題 No.29 パワーアップ
ユーザー sjgq5302sjgq5302
提出日時 2017-08-26 20:18:28
言語 Ruby
(3.3.0)
結果
AC  
実行時間 81 ms / 5,000 ms
コード長 822 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-04-23 17:19:15
合計ジャッジ時間 2,476 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
12,160 KB
testcase_01 AC 75 ms
12,288 KB
testcase_02 AC 75 ms
12,032 KB
testcase_03 AC 75 ms
12,288 KB
testcase_04 AC 75 ms
12,160 KB
testcase_05 AC 77 ms
11,904 KB
testcase_06 AC 77 ms
12,160 KB
testcase_07 AC 81 ms
11,904 KB
testcase_08 AC 78 ms
12,160 KB
testcase_09 AC 76 ms
12,288 KB
testcase_10 AC 75 ms
12,160 KB
testcase_11 AC 75 ms
12,032 KB
testcase_12 AC 77 ms
12,160 KB
testcase_13 AC 77 ms
12,160 KB
testcase_14 AC 76 ms
12,160 KB
testcase_15 AC 74 ms
12,288 KB
testcase_16 AC 75 ms
12,160 KB
testcase_17 AC 77 ms
12,160 KB
testcase_18 AC 76 ms
11,904 KB
testcase_19 AC 76 ms
12,288 KB
testcase_20 AC 75 ms
12,160 KB
testcase_21 AC 75 ms
12,032 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

input = []
while line = gets     #入力のEOF(nil)に達するまで各行を読み込んでline変数に代入するwhile処理
    line.chomp!
    input << line
end


battle_num = input[0].to_i #バトル回数
get_item = [] #手に入れたすべてのアイテムのリスト
item_variety = [] #手に入れたアイテムの種類リスト
powerup = 0 #パワーアップ回数

for i in 1..battle_num
    get_item << input[i].split(" ")
    item_variety << input[i].split(" ")
end

get_item.flatten! #多次元を1次元のリストに
item_variety.flatten!.sort!.uniq! #配列をソートして重複を排除

#同種類パワーアップ
item_variety.each{|j|
    powerup += get_item.count(j) / 2 if get_item.count(j) >= 2
}

#4個パワーアップ
powerup += (get_item.length - (powerup * 2)) / 4

puts powerup
0