結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー tentententen
提出日時 2023-05-30 08:41:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 768 ms / 2,000 ms
コード長 3,192 bytes
コンパイル時間 4,803 ms
コンパイル使用メモリ 81,212 KB
実行使用メモリ 71,936 KB
最終ジャッジ日時 2023-08-28 00:25:29
合計ジャッジ時間 55,098 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
33,700 KB
testcase_01 AC 40 ms
33,728 KB
testcase_02 AC 423 ms
49,644 KB
testcase_03 AC 405 ms
49,184 KB
testcase_04 AC 437 ms
48,648 KB
testcase_05 AC 391 ms
46,552 KB
testcase_06 AC 431 ms
48,252 KB
testcase_07 AC 384 ms
45,608 KB
testcase_08 AC 499 ms
65,940 KB
testcase_09 AC 482 ms
68,100 KB
testcase_10 AC 460 ms
63,260 KB
testcase_11 AC 549 ms
61,436 KB
testcase_12 AC 468 ms
58,132 KB
testcase_13 AC 560 ms
69,976 KB
testcase_14 AC 505 ms
57,468 KB
testcase_15 AC 452 ms
61,368 KB
testcase_16 AC 509 ms
58,812 KB
testcase_17 AC 529 ms
63,160 KB
testcase_18 AC 630 ms
71,936 KB
testcase_19 AC 698 ms
70,392 KB
testcase_20 AC 588 ms
62,640 KB
testcase_21 AC 686 ms
64,132 KB
testcase_22 AC 640 ms
61,012 KB
testcase_23 AC 640 ms
66,372 KB
testcase_24 AC 640 ms
65,288 KB
testcase_25 AC 649 ms
62,172 KB
testcase_26 AC 593 ms
65,964 KB
testcase_27 AC 655 ms
61,104 KB
testcase_28 AC 672 ms
64,404 KB
testcase_29 AC 631 ms
67,380 KB
testcase_30 AC 745 ms
62,536 KB
testcase_31 AC 576 ms
65,096 KB
testcase_32 AC 597 ms
66,784 KB
testcase_33 AC 554 ms
66,812 KB
testcase_34 AC 591 ms
62,016 KB
testcase_35 AC 688 ms
59,968 KB
testcase_36 AC 700 ms
61,680 KB
testcase_37 AC 619 ms
62,892 KB
testcase_38 AC 439 ms
49,728 KB
testcase_39 AC 531 ms
56,588 KB
testcase_40 AC 486 ms
51,340 KB
testcase_41 AC 505 ms
51,272 KB
testcase_42 AC 680 ms
61,036 KB
testcase_43 AC 768 ms
65,352 KB
testcase_44 AC 556 ms
67,460 KB
testcase_45 AC 585 ms
66,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int t = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        while (t-- > 0) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            HashSet<Integer> red = new HashSet<>();
            for (int i = 0; i < n; i++) {
                red.add(sc.nextInt());
            }
            HashSet<Integer> blue = new HashSet<>();
            TreeSet<Integer> both = new TreeSet<>();
            for (int i = 0; i < m; i++) {
                int x = sc.nextInt();
                if (red.contains(x)) {
                    red.remove(x);
                    both.add(x);
                } else {
                    blue.add(x);
                }
            }
            if (both.size() == 0 && red.size() > 0 && blue.size() > 0) {
                sb.append("No\n");
                continue;
            }
            sb.append("Yes\n");
            for (int x : red) {
                sb.append("Red ").append(x).append("\n");
            }
            if (both.size() > 0) {
                int y = both.pollFirst();
                sb.append("Red ").append(y).append("\n");
                sb.append("Blue ").append(y).append("\n");
            }
            for (int x : blue) {
                sb.append("Blue ").append(x).append("\n");
            }
            boolean isBlue = true;
            for (int x : both) {
                if (isBlue) {
                    sb.append("Blue ").append(x).append("\n");
                    sb.append("Red ").append(x).append("\n");
                } else {
                    sb.append("Red ").append(x).append("\n");
                    sb.append("Blue ").append(x).append("\n");
                }
                isBlue ^= true;
            }
        }
        System.out.print(sb);
    }
}

class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0