結果
| 問題 | No.29 パワーアップ |
| コンテスト | |
| ユーザー |
sjgq5302
|
| 提出日時 | 2017-08-26 20:18:28 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 86 ms / 5,000 ms |
| コード長 | 822 bytes |
| 記録 | |
| コンパイル時間 | 59 ms |
| コンパイル使用メモリ | 8,064 KB |
| 実行使用メモリ | 13,184 KB |
| 最終ジャッジ日時 | 2025-10-24 21:02:42 |
| 合計ジャッジ時間 | 2,821 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
コンパイルメッセージ
Syntax OK
ソースコード
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
sjgq5302