結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー haihamabossuhaihamabossu
提出日時 2023-05-19 22:01:01
言語 Rust
(1.77.0)
結果
AC  
実行時間 424 ms / 2,000 ms
コード長 2,993 bytes
コンパイル時間 2,998 ms
コンパイル使用メモリ 157,440 KB
実行使用メモリ 16,044 KB
最終ジャッジ日時 2023-08-23 03:08:52
合計ジャッジ時間 37,926 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 185 ms
4,376 KB
testcase_03 AC 187 ms
4,380 KB
testcase_04 AC 184 ms
4,380 KB
testcase_05 AC 179 ms
4,380 KB
testcase_06 AC 185 ms
4,376 KB
testcase_07 AC 142 ms
4,380 KB
testcase_08 AC 206 ms
6,524 KB
testcase_09 AC 210 ms
6,880 KB
testcase_10 AC 173 ms
7,244 KB
testcase_11 AC 264 ms
7,092 KB
testcase_12 AC 175 ms
9,056 KB
testcase_13 AC 329 ms
7,756 KB
testcase_14 AC 211 ms
7,748 KB
testcase_15 AC 159 ms
6,308 KB
testcase_16 AC 274 ms
5,696 KB
testcase_17 AC 213 ms
6,968 KB
testcase_18 AC 338 ms
15,236 KB
testcase_19 AC 382 ms
13,672 KB
testcase_20 AC 348 ms
14,584 KB
testcase_21 AC 367 ms
16,044 KB
testcase_22 AC 343 ms
13,832 KB
testcase_23 AC 359 ms
14,544 KB
testcase_24 AC 372 ms
13,796 KB
testcase_25 AC 364 ms
13,740 KB
testcase_26 AC 341 ms
14,444 KB
testcase_27 AC 367 ms
13,684 KB
testcase_28 AC 358 ms
14,360 KB
testcase_29 AC 362 ms
14,084 KB
testcase_30 AC 376 ms
15,700 KB
testcase_31 AC 336 ms
14,584 KB
testcase_32 AC 333 ms
15,796 KB
testcase_33 AC 342 ms
13,828 KB
testcase_34 AC 364 ms
13,408 KB
testcase_35 AC 383 ms
13,672 KB
testcase_36 AC 367 ms
14,340 KB
testcase_37 AC 372 ms
15,048 KB
testcase_38 AC 327 ms
4,376 KB
testcase_39 AC 424 ms
4,376 KB
testcase_40 AC 306 ms
4,380 KB
testcase_41 AC 332 ms
4,380 KB
testcase_42 AC 379 ms
13,788 KB
testcase_43 AC 380 ms
13,736 KB
testcase_44 AC 337 ms
14,828 KB
testcase_45 AC 339 ms
14,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

pub mod scanner {

    pub struct Scanner {
        buf: Vec<String>,
    }

    impl Scanner {
        pub fn new() -> Self {
            Self { buf: vec![] }
        }

        pub fn new_from(source: &str) -> Self {
            let source = String::from(source);
            let buf = Self::split(source);
            Self { buf }
        }

        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            loop {
                if let Some(x) = self.buf.pop() {
                    return x.parse().ok().expect("");
                }
                let mut source = String::new();
                std::io::stdin().read_line(&mut source).expect("");
                self.buf = Self::split(source);
            }
        }

        fn split(source: String) -> Vec<String> {
            source
                .split_whitespace()
                .rev()
                .map(String::from)
                .collect::<Vec<_>>()
        }
    }
}

use std::collections::{BTreeMap, BTreeSet, BinaryHeap};

use crate::scanner::Scanner;

fn main() {
    let mut scanner = Scanner::new();
    let t: usize = scanner.next();
    for _ in 0..t {
        solve(&mut scanner);
    }
}

fn solve(scanner: &mut Scanner) {
    let n: usize = scanner.next();
    let m: usize = scanner.next();
    let mut count = BTreeMap::new();
    let a: Vec<usize> = (0..n)
        .map(|_| {
            let x = scanner.next::<usize>();
            *count.entry(x).or_insert(0) += 1;
            x
        })
        .collect();
    let b: Vec<usize> = (0..m)
        .map(|_| {
            let x = scanner.next::<usize>();
            *count.entry(x).or_insert(0) += 1;
            x
        })
        .collect();
    if n == 0 || m == 0 {
        println!("Yes");
        if n == 0 {
            for i in 0..m {
                println!("Blue {}", b[i]);
            }
        } else {
            for i in 0..n {
                println!("Red {}", a[i]);
            }
        }
        return;
    }
    let mut c = BTreeSet::new();
    let mut q = BinaryHeap::new();
    for (&k, &v) in count.iter() {
        if v == 2 {
            c.insert(k);
            q.push(k);
        }
    }
    let c = c;
    if c.len() == 0 {
        println!("No");
        return;
    }
    println!("Yes");
    for i in 0..n {
        if c.contains(&a[i]) {
            continue;
        } else {
            println!("Red {}", a[i]);
        }
    }
    {
        let now = q.pop().unwrap();
        println!("Red {}", now);
        println!("Blue {}", now);
    }
    for i in 0..m {
        if c.contains(&b[i]) {
            continue;
        } else {
            println!("Blue {}", b[i]);
        }
    }
    let mut turn = 1;
    while let Some(now) = q.pop() {
        if turn == 0 {
            println!("Red {}", now);
            println!("Blue {}", now);
            turn = 1;
        } else {
            println!("Blue {}", now);
            println!("Red {}", now);
            turn = 0;
        }
    }
}
0