結果

問題 No.628 Tagの勢い
ユーザー gemmaro
提出日時 2020-03-06 15:48:20
言語 Ruby
(3.4.1)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 563 bytes
コンパイル時間 56 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-10-14 02:52:13
合計ジャッジ時間 2,834 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# frozen_string_literal: true

Image = Struct.new(:num, :score, :tags)

N = gets.to_i
IMAGES = N.times.map do
  n = gets.to_i
  _m, s = gets.chomp.split.map(&:to_i)
  tags = gets.chomp.split
  Image.new(n, s, tags)
end

tags = {}
IMAGES.each do |image|
  image.tags.each do |tag|
    tags[tag] ||= 0
    tags[tag] += image.score
  end
end
tags = tags.to_a

ORDERED = tags.sort { |a, b| a[1] == b[1] ? a[0] <=> b[0] : b[1] <=> a[1] }
              .compact.map { |tag, score| "#{tag} #{score}" }

RESULT = ORDERED[0, [10, ORDERED.size].min].join("\n")

puts RESULT
0