結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー ks2mks2m
提出日時 2023-05-19 21:46:29
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,591 bytes
コンパイル時間 4,306 ms
コンパイル使用メモリ 77,008 KB
実行使用メモリ 98,200 KB
最終ジャッジ日時 2023-08-23 02:49:57
合計ジャッジ時間 57,937 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
50,720 KB
testcase_01 AC 55 ms
34,168 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 661 ms
67,160 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 901 ms
79,756 KB
testcase_19 WA -
testcase_20 AC 830 ms
95,532 KB
testcase_21 AC 818 ms
91,092 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 928 ms
78,176 KB
testcase_28 WA -
testcase_29 AC 878 ms
94,420 KB
testcase_30 WA -
testcase_31 AC 819 ms
93,748 KB
testcase_32 WA -
testcase_33 AC 899 ms
88,612 KB
testcase_34 AC 939 ms
88,396 KB
testcase_35 AC 933 ms
87,860 KB
testcase_36 WA -
testcase_37 AC 872 ms
77,496 KB
testcase_38 AC 608 ms
59,848 KB
testcase_39 AC 751 ms
59,480 KB
testcase_40 AC 549 ms
58,664 KB
testcase_41 AC 586 ms
60,596 KB
testcase_42 AC 888 ms
88,220 KB
testcase_43 AC 900 ms
87,336 KB
testcase_44 AC 796 ms
89,536 KB
testcase_45 AC 723 ms
88,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		PrintWriter pw = new PrintWriter(System.out);
		for (int z = 0; z < t; z++) {
			String[] sa = br.readLine().split(" ");
			int n = Integer.parseInt(sa[0]);
			int m = Integer.parseInt(sa[1]);
			sa = br.readLine().split(" ");
			int[] a = new int[n];
			Set<Integer> seta = new HashSet<>();
			for (int i = 0; i < n; i++) {
				a[i] = Integer.parseInt(sa[i]);
				seta.add(a[i]);
			}
			sa = br.readLine().split(" ");
			int[] b = new int[m];
			Set<Integer> setb = new HashSet<>();
			for (int i = 0; i < m; i++) {
				b[i] = Integer.parseInt(sa[i]);
				setb.add(b[i]);
			}

			seta.retainAll(setb);
			if (seta.isEmpty()) {
				if (n == 0 || m == 0) {
					pw.println("Yes");
					if (n == 0) {
						for (int i = 0; i < m; i++) {
							pw.println("Blue " + b[i]);
						}
					} else {
						for (int i = 0; i < n; i++) {
							pw.println("Red " + a[i]);
						}
					}
				} else {
					pw.println("No");
				}
			} else {
				pw.println("Yes");
				if (seta.size() % 2 == 0 && seta.size() != n && seta.size() != m) {
					Integer e = seta.iterator().next();
					seta.remove(e);
				}
				if (seta.size() < n) {
					for (int i = 0; i < n; i++) {
						if (!seta.contains(a[i])) {
							pw.println("Red " + a[i]);
						}
					}
					Integer[] arr = seta.toArray(new Integer[0]);
					for (int i = 0; i < arr.length; i++) {
						if (i % 2 == 0) {
							pw.println("Red " + arr[i]);
							pw.println("Blue " + arr[i]);
						} else {
							pw.println("Blue " + arr[i]);
							pw.println("Red " + arr[i]);
						}
					}
					for (int i = 0; i < m; i++) {
						if (!seta.contains(b[i])) {
							pw.println("Blue " + b[i]);
						}
					}
				} else {
					for (int i = 0; i < m; i++) {
						if (!seta.contains(b[i])) {
							pw.println("Blue " + b[i]);
						}
					}
					Integer[] arr = seta.toArray(new Integer[0]);
					for (int i = 0; i < arr.length; i++) {
						if (i % 2 == 0) {
							pw.println("Blue " + arr[i]);
							pw.println("Red " + arr[i]);
						} else {
							pw.println("Red " + arr[i]);
							pw.println("Blue " + arr[i]);
						}
					}
					for (int i = 0; i < n; i++) {
						if (!seta.contains(a[i])) {
							pw.println("Red " + a[i]);
						}
					}
				}
			}
		}
		pw.flush();
		br.close();

	}
}
0