結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー simansiman
提出日時 2023-05-20 07:59:55
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,192 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 11,464 KB
実行使用メモリ 46,828 KB
最終ジャッジ日時 2023-08-23 06:46:40
合計ジャッジ時間 40,057 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,264 KB
testcase_01 AC 81 ms
15,144 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 359 ms
27,412 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 417 ms
41,204 KB
testcase_19 WA -
testcase_20 AC 430 ms
41,828 KB
testcase_21 AC 444 ms
41,056 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 439 ms
41,520 KB
testcase_28 WA -
testcase_29 AC 439 ms
40,288 KB
testcase_30 WA -
testcase_31 AC 424 ms
41,736 KB
testcase_32 WA -
testcase_33 AC 406 ms
44,320 KB
testcase_34 AC 454 ms
41,812 KB
testcase_35 AC 493 ms
45,652 KB
testcase_36 WA -
testcase_37 AC 437 ms
41,972 KB
testcase_38 AC 504 ms
15,408 KB
testcase_39 AC 652 ms
15,304 KB
testcase_40 AC 295 ms
15,592 KB
testcase_41 AC 364 ms
16,032 KB
testcase_42 AC 501 ms
46,796 KB
testcase_43 AC 505 ms
46,828 KB
testcase_44 AC 335 ms
34,468 KB
testcase_45 AC 335 ms
34,420 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

T = gets.to_i

T.times do
  n, m = gets.split.map(&:to_i)
  a = gets.split.map(&:to_i).sort
  b = gets.split.map(&:to_i).sort

  if n == 0
    puts 'Yes'
    b.each do |x|
      puts "Blue #{x}"
    end
  elsif m == 0
    puts 'Yes'
    a.each do |x|
      puts "Red #{x}"
    end
  else
    a_cnt = a.tally
    b_cnt = b.tally
    c = a & b
    c_cnt = c.tally

    if c.empty?
      puts 'No'
    else
      puts 'Yes'

      t = 0
      ans = []

      c.each do |x|
        cnt = [a_cnt[x], b_cnt[x]].min

        cnt.times do
          if t.even?
            ans << "Red #{x}"
            ans << "Blue #{x}"
          else
            ans << "Blue #{x}"
            ans << "Red #{x}"
          end

          t += 1
        end
      end

      if t.even?
        a.each do |x|
          next if c_cnt[x]

          ans << "Red #{x}"
        end

        b.each do |x|
          next if c_cnt[x]

          ans.unshift("Blue #{x}")
        end
      else
        b.each do |x|
          next if c_cnt[x]

          ans << "Blue #{x}"
        end

        a.each do |x|
          next if c_cnt[x]

          ans.unshift("Red #{x}")
        end
      end

      puts ans
    end
  end
end
0