結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー simansiman
提出日時 2023-05-20 08:09:30
言語 Ruby
(3.3.0)
結果
AC  
実行時間 663 ms / 2,000 ms
コード長 1,252 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 11,172 KB
実行使用メモリ 46,988 KB
最終ジャッジ日時 2023-08-23 06:50:40
合計ジャッジ時間 39,261 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,220 KB
testcase_01 AC 78 ms
14,980 KB
testcase_02 AC 274 ms
15,544 KB
testcase_03 AC 271 ms
18,476 KB
testcase_04 AC 262 ms
19,004 KB
testcase_05 AC 264 ms
18,220 KB
testcase_06 AC 259 ms
17,716 KB
testcase_07 AC 237 ms
17,580 KB
testcase_08 AC 302 ms
29,312 KB
testcase_09 AC 302 ms
25,284 KB
testcase_10 AC 276 ms
28,764 KB
testcase_11 AC 353 ms
27,332 KB
testcase_12 AC 275 ms
31,220 KB
testcase_13 AC 374 ms
32,776 KB
testcase_14 AC 302 ms
30,692 KB
testcase_15 AC 264 ms
26,360 KB
testcase_16 AC 330 ms
25,380 KB
testcase_17 AC 307 ms
32,440 KB
testcase_18 AC 417 ms
41,480 KB
testcase_19 AC 497 ms
46,340 KB
testcase_20 AC 430 ms
41,816 KB
testcase_21 AC 430 ms
41,160 KB
testcase_22 AC 396 ms
41,756 KB
testcase_23 AC 426 ms
41,616 KB
testcase_24 AC 430 ms
42,256 KB
testcase_25 AC 411 ms
41,672 KB
testcase_26 AC 415 ms
41,140 KB
testcase_27 AC 424 ms
41,280 KB
testcase_28 AC 433 ms
40,868 KB
testcase_29 AC 427 ms
40,312 KB
testcase_30 AC 465 ms
45,840 KB
testcase_31 AC 409 ms
41,632 KB
testcase_32 AC 405 ms
41,184 KB
testcase_33 AC 401 ms
44,448 KB
testcase_34 AC 439 ms
41,684 KB
testcase_35 AC 479 ms
45,564 KB
testcase_36 AC 439 ms
41,944 KB
testcase_37 AC 423 ms
41,512 KB
testcase_38 AC 504 ms
15,120 KB
testcase_39 AC 663 ms
15,216 KB
testcase_40 AC 291 ms
15,740 KB
testcase_41 AC 360 ms
16,144 KB
testcase_42 AC 477 ms
46,988 KB
testcase_43 AC 487 ms
46,760 KB
testcase_44 AC 330 ms
34,660 KB
testcase_45 AC 335 ms
34,552 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?
        l1, l2 = ans.pop(2)

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

          ans << "Blue #{x}"
        end

        ans << l1
        ans << l2

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

          ans << "Red #{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