結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー tipstar0125tipstar0125
提出日時 2023-05-19 22:07:07
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 5,300 bytes
コンパイル時間 28,213 ms
コンパイル使用メモリ 380,636 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-01 00:58:31
合計ジャッジ時間 37,971 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 36 ms
6,940 KB
testcase_03 AC 39 ms
6,944 KB
testcase_04 AC 39 ms
6,944 KB
testcase_05 AC 39 ms
6,940 KB
testcase_06 AC 39 ms
6,940 KB
testcase_07 AC 37 ms
6,944 KB
testcase_08 AC 43 ms
6,940 KB
testcase_09 AC 43 ms
6,944 KB
testcase_10 AC 42 ms
6,944 KB
testcase_11 AC 48 ms
6,940 KB
testcase_12 AC 42 ms
6,944 KB
testcase_13 AC 52 ms
6,944 KB
testcase_14 AC 44 ms
6,944 KB
testcase_15 AC 40 ms
6,940 KB
testcase_16 AC 47 ms
6,944 KB
testcase_17 AC 44 ms
6,944 KB
testcase_18 AC 57 ms
6,940 KB
testcase_19 AC 55 ms
6,940 KB
testcase_20 AC 56 ms
6,944 KB
testcase_21 AC 57 ms
6,940 KB
testcase_22 AC 56 ms
6,944 KB
testcase_23 AC 57 ms
6,940 KB
testcase_24 AC 57 ms
6,944 KB
testcase_25 AC 58 ms
6,940 KB
testcase_26 AC 58 ms
6,940 KB
testcase_27 AC 56 ms
6,940 KB
testcase_28 AC 57 ms
6,944 KB
testcase_29 AC 56 ms
6,940 KB
testcase_30 AC 55 ms
6,944 KB
testcase_31 AC 58 ms
6,940 KB
testcase_32 AC 57 ms
6,940 KB
testcase_33 AC 56 ms
6,940 KB
testcase_34 AC 58 ms
6,940 KB
testcase_35 AC 57 ms
6,944 KB
testcase_36 AC 56 ms
6,940 KB
testcase_37 AC 58 ms
6,940 KB
testcase_38 AC 38 ms
6,944 KB
testcase_39 AC 57 ms
6,940 KB
testcase_40 AC 39 ms
6,944 KB
testcase_41 AC 44 ms
6,940 KB
testcase_42 AC 54 ms
6,940 KB
testcase_43 AC 53 ms
6,940 KB
testcase_44 AC 49 ms
6,944 KB
testcase_45 AC 48 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(clippy::needless_range_loop)]
#![allow(clippy::comparison_chain)]
#![allow(clippy::nonminimal_bool)]
#![allow(clippy::neg_multiply)]
#![allow(dead_code)]
// use itertools::Itertools;
// use superslice::Ext;
use std::cmp::Reverse;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

#[derive(Default)]
struct Solver {}
impl Solver {
    fn solve(&mut self) {
        input! {
            T: usize,
        }

        for _ in 0..T {
            input! {
                N: usize,
                M: usize,
                A: [usize; N],
                B: [usize; M]
            }

            let A: BTreeSet<usize> = A.into_iter().collect();
            let B: BTreeSet<usize> = B.into_iter().collect();

            if A.is_empty() {
                println!("Yes");
                for b in B.iter() {
                    println!("Blue {}", b);
                }
                continue;
            }
            if B.is_empty() {
                println!("Yes");
                for a in A.iter() {
                    println!("Red {}", a);
                }
                continue;
            }

            let mut C = &A & &B;
            if C.is_empty() {
                println!("No");
            } else {
                println!("Yes");
                let A = &A - &C;
                let B = &B - &C;

                for a in A.iter() {
                    println!("Red {}", a);
                }

                let c1 = C.pop_first().unwrap();
                println!("Red {}", c1);
                println!("Blue {}", c1);

                for b in B.iter() {
                    println!("Blue {}", b);
                }

                for (i, c) in C.iter().enumerate() {
                    if i % 2 == 0 {
                        println!("Blue {}", c);
                        println!("Red {}", c);
                    } else {
                        println!("Red {}", c);
                        println!("Blue {}", c);
                    }
                }
            }
        }
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(128 * 1024 * 1024)
        .spawn(|| Solver::default().solve())
        .unwrap()
        .join()
        .unwrap();
}

#[macro_export]
macro_rules! input {
    () => {};
    (mut $var:ident: $t:tt, $($rest:tt)*) => {
        let mut $var = __input_inner!($t);
        input!($($rest)*)
    };
    ($var:ident: $t:tt, $($rest:tt)*) => {
        let $var = __input_inner!($t);
        input!($($rest)*)
    };
    (mut $var:ident: $t:tt) => {
        let mut $var = __input_inner!($t);
    };
    ($var:ident: $t:tt) => {
        let $var = __input_inner!($t);
    };
}

#[macro_export]
macro_rules! __input_inner {
    (($($t:tt),*)) => {
        ($(__input_inner!($t)),*)
    };
    ([$t:tt; $n:expr]) => {
        (0..$n).map(|_| __input_inner!($t)).collect::<Vec<_>>()
    };
    ([$t:tt]) => {{
        let n = __input_inner!(usize);
        (0..n).map(|_| __input_inner!($t)).collect::<Vec<_>>()
    }};
    (chars) => {
        __input_inner!(String).chars().collect::<Vec<_>>()
    };
    (bytes) => {
        __input_inner!(String).into_bytes()
    };
    (usize1) => {
        __input_inner!(usize) - 1
    };
    ($t:ty) => {
        $crate::read::<$t>()
    };
}

#[macro_export]
macro_rules! println {
    () => {
        $crate::write(|w| {
            use std::io::Write;
            std::writeln!(w).unwrap()
        })
    };
    ($($arg:tt)*) => {
        $crate::write(|w| {
            use std::io::Write;
            std::writeln!(w, $($arg)*).unwrap()
        })
    };
}

#[macro_export]
macro_rules! print {
    ($($arg:tt)*) => {
        $crate::write(|w| {
            use std::io::Write;
            std::write!(w, $($arg)*).unwrap()
        })
    };
}

#[macro_export]
macro_rules! flush {
    () => {
        $crate::write(|w| {
            use std::io::Write;
            w.flush().unwrap()
        })
    };
}

pub fn read<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    use std::cell::RefCell;
    use std::io::*;

    thread_local! {
        pub static STDIN: RefCell<StdinLock<'static>> = RefCell::new(stdin().lock());
    }

    STDIN.with(|r| {
        let mut r = r.borrow_mut();
        let mut s = vec![];
        loop {
            let buf = r.fill_buf().unwrap();
            if buf.is_empty() {
                break;
            }
            if let Some(i) = buf.iter().position(u8::is_ascii_whitespace) {
                s.extend_from_slice(&buf[..i]);
                r.consume(i + 1);
                if !s.is_empty() {
                    break;
                }
            } else {
                s.extend_from_slice(buf);
                let n = buf.len();
                r.consume(n);
            }
        }
        std::str::from_utf8(&s).unwrap().parse().unwrap()
    })
}

pub fn write<F>(f: F)
where
    F: FnOnce(&mut std::io::BufWriter<std::io::StdoutLock>),
{
    use std::cell::RefCell;
    use std::io::*;

    thread_local! {
        pub static STDOUT: RefCell<BufWriter<StdoutLock<'static>>> =
            RefCell::new(BufWriter::new(stdout().lock()));
    }

    STDOUT.with(|w| f(&mut w.borrow_mut()))
}
0