結果

問題 No.29 パワーアップ
ユーザー sjgq5302sjgq5302
提出日時 2017-08-26 20:18:28
言語 Ruby
(3.3.0)
結果
AC  
実行時間 75 ms / 5,000 ms
コード長 822 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 11,320 KB
実行使用メモリ 15,260 KB
最終ジャッジ日時 2023-08-05 20:50:16
合計ジャッジ時間 3,380 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
15,244 KB
testcase_01 AC 69 ms
15,108 KB
testcase_02 AC 73 ms
15,096 KB
testcase_03 AC 69 ms
15,028 KB
testcase_04 AC 68 ms
15,260 KB
testcase_05 AC 68 ms
15,068 KB
testcase_06 AC 69 ms
15,104 KB
testcase_07 AC 70 ms
15,068 KB
testcase_08 AC 69 ms
15,096 KB
testcase_09 AC 68 ms
15,104 KB
testcase_10 AC 68 ms
15,020 KB
testcase_11 AC 70 ms
15,104 KB
testcase_12 AC 69 ms
15,000 KB
testcase_13 AC 70 ms
15,000 KB
testcase_14 AC 68 ms
15,020 KB
testcase_15 AC 71 ms
15,084 KB
testcase_16 AC 72 ms
15,240 KB
testcase_17 AC 74 ms
15,156 KB
testcase_18 AC 75 ms
15,068 KB
testcase_19 AC 74 ms
15,060 KB
testcase_20 AC 75 ms
15,140 KB
testcase_21 AC 70 ms
15,088 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